2016-06-08 07:25:08 +02:00
|
|
|
/**
|
2017-07-27 13:45:37 +02:00
|
|
|
* @file lv_cont.c
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2016-06-08 07:25:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2016-10-07 11:15:46 +02:00
|
|
|
|
2018-07-07 11:53:22 +02:00
|
|
|
#include "lv_cont.h"
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_CONT != 0
|
2016-06-22 21:52:39 +02:00
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-09-24 16:30:38 +02:00
|
|
|
#include "../lv_core/lv_debug.h"
|
2016-06-08 07:25:08 +02:00
|
|
|
#include "../lv_draw/lv_draw.h"
|
2019-09-06 19:53:39 +02:00
|
|
|
#include "../lv_draw/lv_draw_mask.h"
|
2017-11-16 15:32:33 +01:00
|
|
|
#include "../lv_themes/lv_theme.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_area.h"
|
|
|
|
#include "../lv_misc/lv_color.h"
|
|
|
|
#include "../lv_misc/lv_math.h"
|
2019-10-14 15:25:40 +02:00
|
|
|
#include "../lv_misc/lv_bidi.h"
|
2016-06-08 07:25:08 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2019-09-26 10:51:54 +02:00
|
|
|
#define LV_OBJX_NAME "lv_cont"
|
2016-06-08 07:25:08 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2017-11-05 00:48:57 +01:00
|
|
|
static lv_res_t lv_cont_signal(lv_obj_t * cont, lv_signal_t sign, void * param);
|
2020-01-16 14:26:36 +01:00
|
|
|
static lv_style_list_t * lv_cont_get_style(lv_obj_t * cont, uint8_t type);
|
2017-04-13 16:12:03 +02:00
|
|
|
static void lv_cont_refr_layout(lv_obj_t * cont);
|
|
|
|
static void lv_cont_layout_col(lv_obj_t * cont);
|
|
|
|
static void lv_cont_layout_row(lv_obj_t * cont);
|
|
|
|
static void lv_cont_layout_center(lv_obj_t * cont);
|
|
|
|
static void lv_cont_layout_pretty(lv_obj_t * cont);
|
|
|
|
static void lv_cont_layout_grid(lv_obj_t * cont);
|
|
|
|
static void lv_cont_refr_autofit(lv_obj_t * cont);
|
2016-06-08 07:25:08 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2019-09-06 19:53:39 +02:00
|
|
|
static lv_design_cb_t ancestor_design;
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_signal_cb_t ancestor_signal;
|
2016-06-08 07:25:08 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
2017-04-13 16:12:03 +02:00
|
|
|
* Create a container objects
|
|
|
|
* @param par pointer to an object, it will be the parent of the new container
|
|
|
|
* @param copy pointer to a container object, if not NULL then the new object will be copied from it
|
|
|
|
* @return pointer to the created container
|
2016-06-08 07:25:08 +02:00
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy)
|
2016-06-08 07:25:08 +02:00
|
|
|
{
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("container create started");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/*Create a basic object*/
|
2020-01-24 14:55:56 +01:00
|
|
|
lv_obj_t * cont = lv_obj_create(par, copy);
|
|
|
|
LV_ASSERT_MEM(cont);
|
|
|
|
if(cont == NULL) return NULL;
|
2018-07-25 13:33:53 +02:00
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(cont);
|
2020-02-26 19:48:27 +01:00
|
|
|
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(cont);
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
lv_obj_allocate_ext_attr(cont, sizeof(lv_cont_ext_t));
|
|
|
|
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
|
2019-12-03 18:16:14 +01:00
|
|
|
if(ext == NULL) {
|
2020-01-24 14:55:56 +01:00
|
|
|
lv_obj_del(cont);
|
2019-12-03 18:16:14 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-25 13:33:53 +02:00
|
|
|
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->fit_left = LV_FIT_NONE;
|
|
|
|
ext->fit_right = LV_FIT_NONE;
|
|
|
|
ext->fit_top = LV_FIT_NONE;
|
2019-02-24 06:24:36 +01:00
|
|
|
ext->fit_bottom = LV_FIT_NONE;
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->layout = LV_LAYOUT_OFF;
|
2017-01-02 14:10:32 +01:00
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
lv_obj_set_signal_cb(cont, lv_cont_signal);
|
2016-06-11 13:41:35 +02:00
|
|
|
|
2017-04-13 16:12:03 +02:00
|
|
|
/*Init the new container*/
|
2016-10-07 11:15:46 +02:00
|
|
|
if(copy == NULL) {
|
2019-06-26 17:51:14 +02:00
|
|
|
/*Set the default styles if it's not screen*/
|
|
|
|
if(par != NULL) {
|
2020-01-24 14:55:56 +01:00
|
|
|
lv_theme_apply(cont, LV_THEME_CONT);
|
2017-11-16 15:32:33 +01:00
|
|
|
}
|
2020-01-24 14:55:56 +01:00
|
|
|
|
|
|
|
|
2016-10-07 11:15:46 +02:00
|
|
|
}
|
|
|
|
/*Copy an existing object*/
|
|
|
|
else {
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_cont_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->fit_left = copy_ext->fit_left;
|
|
|
|
ext->fit_right = copy_ext->fit_right;
|
|
|
|
ext->fit_top = copy_ext->fit_top;
|
|
|
|
ext->fit_bottom = copy_ext->fit_bottom;
|
|
|
|
ext->layout = copy_ext->layout;
|
2017-01-02 14:10:32 +01:00
|
|
|
|
2017-01-08 13:06:41 +01:00
|
|
|
/*Refresh the style with new signal function*/
|
2020-03-10 10:41:39 +01:00
|
|
|
lv_obj_refresh_style(cont, LV_STYLE_PROP_ALL);
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("container created");
|
2018-07-25 20:39:24 +02:00
|
|
|
|
2020-01-24 14:55:56 +01:00
|
|
|
return cont;
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
|
|
|
|
2016-06-15 09:38:20 +02:00
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
2016-10-07 11:15:46 +02:00
|
|
|
/**
|
2017-11-05 00:48:57 +01:00
|
|
|
* Set a layout on a container
|
2017-04-13 16:12:03 +02:00
|
|
|
* @param cont pointer to a container object
|
|
|
|
* @param layout a layout from 'lv_cont_layout_t'
|
2016-10-07 11:15:46 +02:00
|
|
|
*/
|
2017-11-17 15:43:08 +01:00
|
|
|
void lv_cont_set_layout(lv_obj_t * cont, lv_layout_t layout)
|
2016-06-22 20:39:07 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(cont, LV_OBJX_NAME);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
|
|
|
|
if(ext->layout == layout) return;
|
2018-05-16 23:09:30 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
ext->layout = layout;
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Send a signal to refresh the layout*/
|
2019-02-26 09:25:46 +01:00
|
|
|
cont->signal_cb(cont, LV_SIGNAL_CHILD_CHG, NULL);
|
2016-06-22 20:39:07 +02:00
|
|
|
}
|
|
|
|
|
2016-06-15 09:38:20 +02:00
|
|
|
/**
|
2019-02-24 06:24:36 +01:00
|
|
|
* Set the fit policy in all 4 directions separately.
|
|
|
|
* It tell how to change the container's size automatically.
|
2017-04-13 16:12:03 +02:00
|
|
|
* @param cont pointer to a container object
|
2019-02-24 06:24:36 +01:00
|
|
|
* @param left left fit policy from `lv_fit_t`
|
|
|
|
* @param right right fit policy from `lv_fit_t`
|
|
|
|
* @param top bottom fit policy from `lv_fit_t`
|
|
|
|
* @param bottom bottom fit policy from `lv_fit_t`
|
2016-06-15 09:38:20 +02:00
|
|
|
*/
|
2019-02-24 06:24:36 +01:00
|
|
|
void lv_cont_set_fit4(lv_obj_t * cont, lv_fit_t left, lv_fit_t right, lv_fit_t top, lv_fit_t bottom)
|
2016-06-15 09:38:20 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(cont, LV_OBJX_NAME);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_invalidate(cont);
|
|
|
|
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
|
2019-06-06 06:05:40 +02:00
|
|
|
if(ext->fit_left == left && ext->fit_right == right && ext->fit_top == top && ext->fit_bottom == bottom) {
|
2019-02-24 06:24:36 +01:00
|
|
|
return;
|
|
|
|
}
|
2018-05-16 23:09:30 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->fit_left = left;
|
|
|
|
ext->fit_right = right;
|
|
|
|
ext->fit_top = top;
|
2019-02-24 06:24:36 +01:00
|
|
|
ext->fit_bottom = bottom;
|
2016-06-15 09:38:20 +02:00
|
|
|
|
2018-08-26 13:49:23 +02:00
|
|
|
/*Send a signal to refresh the layout*/
|
2019-02-26 09:25:46 +01:00
|
|
|
cont->signal_cb(cont, LV_SIGNAL_CHILD_CHG, NULL);
|
2016-06-15 09:38:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
|
|
|
|
2016-10-07 11:15:46 +02:00
|
|
|
/**
|
2017-04-13 16:12:03 +02:00
|
|
|
* Get the layout of a container
|
|
|
|
* @param cont pointer to container object
|
|
|
|
* @return the layout from 'lv_cont_layout_t'
|
2016-10-07 11:15:46 +02:00
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_layout_t lv_cont_get_layout(const lv_obj_t * cont)
|
2016-06-22 20:39:07 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(cont, LV_OBJX_NAME);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
|
|
|
|
return ext->layout;
|
2016-06-22 20:39:07 +02:00
|
|
|
}
|
|
|
|
|
2016-06-15 09:38:20 +02:00
|
|
|
/**
|
2019-02-24 06:24:36 +01:00
|
|
|
* Get left fit mode of a container
|
2017-04-13 16:12:03 +02:00
|
|
|
* @param cont pointer to a container object
|
2019-02-24 06:24:36 +01:00
|
|
|
* @return an element of `lv_fit_t`
|
2016-06-15 09:38:20 +02:00
|
|
|
*/
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_fit_t lv_cont_get_fit_left(const lv_obj_t * cont)
|
2016-06-15 09:38:20 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(cont, LV_OBJX_NAME);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
|
2019-02-24 06:24:36 +01:00
|
|
|
return ext->fit_left;
|
2016-06-15 09:38:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-24 06:24:36 +01:00
|
|
|
* Get right fit mode of a container
|
2017-04-13 16:12:03 +02:00
|
|
|
* @param cont pointer to a container object
|
2019-02-24 06:24:36 +01:00
|
|
|
* @return an element of `lv_fit_t`
|
2016-06-15 09:38:20 +02:00
|
|
|
*/
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_fit_t lv_cont_get_fit_right(const lv_obj_t * cont)
|
2016-06-15 09:38:20 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(cont, LV_OBJX_NAME);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
|
2019-02-24 06:24:36 +01:00
|
|
|
return ext->fit_right;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get top fit mode of a container
|
|
|
|
* @param cont pointer to a container object
|
|
|
|
* @return an element of `lv_fit_t`
|
|
|
|
*/
|
|
|
|
lv_fit_t lv_cont_get_fit_top(const lv_obj_t * cont)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(cont, LV_OBJX_NAME);
|
|
|
|
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
|
|
|
|
return ext->fit_top;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get bottom fit mode of a container
|
|
|
|
* @param cont pointer to a container object
|
|
|
|
* @return an element of `lv_fit_t`
|
|
|
|
*/
|
|
|
|
lv_fit_t lv_cont_get_fit_bottom(const lv_obj_t * cont)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(cont, LV_OBJX_NAME);
|
|
|
|
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
|
|
|
|
return ext->fit_bottom;
|
2016-06-15 09:38:20 +02:00
|
|
|
}
|
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
2020-04-14 11:06:56 +02:00
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/**
|
2017-11-05 00:48:57 +01:00
|
|
|
* Signal function of the container
|
|
|
|
* @param cont pointer to a container object
|
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
2016-06-08 07:25:08 +02:00
|
|
|
*/
|
2017-11-05 00:48:57 +01:00
|
|
|
static lv_res_t lv_cont_signal(lv_obj_t * cont, lv_signal_t sign, void * param)
|
2016-06-08 07:25:08 +02:00
|
|
|
{
|
2019-12-17 09:20:40 +01:00
|
|
|
if(sign == LV_SIGNAL_GET_STYLE) {
|
2020-01-07 23:43:57 +01:00
|
|
|
lv_get_style_info_t * info = param;
|
|
|
|
info->result = lv_cont_get_style(cont, info->part);
|
|
|
|
if(info->result != NULL) return LV_RES_OK;
|
|
|
|
else return ancestor_signal(cont, sign, param);
|
2019-12-17 09:20:40 +01:00
|
|
|
}
|
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
lv_res_t res;
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_signal(cont, sign, param);
|
2017-11-07 17:00:55 +01:00
|
|
|
if(res != LV_RES_OK) return res;
|
2019-09-26 12:54:40 +02:00
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
|
2017-11-07 17:00:55 +01:00
|
|
|
|
|
|
|
if(sign == LV_SIGNAL_STYLE_CHG) { /*Recalculate the padding if the style changed*/
|
|
|
|
lv_cont_refr_layout(cont);
|
|
|
|
lv_cont_refr_autofit(cont);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_CHILD_CHG) {
|
2017-11-07 17:00:55 +01:00
|
|
|
lv_cont_refr_layout(cont);
|
|
|
|
lv_cont_refr_autofit(cont);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_COORD_CHG) {
|
2019-06-06 06:05:40 +02:00
|
|
|
if(lv_obj_get_width(cont) != lv_area_get_width(param) || lv_obj_get_height(cont) != lv_area_get_height(param)) {
|
2017-11-05 00:48:57 +01:00
|
|
|
lv_cont_refr_layout(cont);
|
|
|
|
lv_cont_refr_autofit(cont);
|
|
|
|
}
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_PARENT_SIZE_CHG) {
|
2020-03-10 10:41:39 +01:00
|
|
|
/*MAX and EDGE fit needs to be refreshed if the parent's size has changed*/
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_cont_refr_autofit(cont);
|
2018-02-28 15:37:41 +01:00
|
|
|
}
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
return res;
|
2016-06-08 07:25:08 +02:00
|
|
|
}
|
2019-12-31 23:02:25 +01:00
|
|
|
|
|
|
|
|
2020-01-16 14:26:36 +01:00
|
|
|
static lv_style_list_t * lv_cont_get_style(lv_obj_t * cont, uint8_t type)
|
2019-12-31 23:02:25 +01:00
|
|
|
{
|
2020-01-16 14:26:36 +01:00
|
|
|
lv_style_list_t * style_dsc_p;
|
2019-12-31 23:02:25 +01:00
|
|
|
switch(type) {
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_CONT_PART_MAIN:
|
|
|
|
style_dsc_p = &cont->style_list;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
style_dsc_p = NULL;
|
2019-12-31 23:02:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return style_dsc_p;
|
|
|
|
}
|
|
|
|
|
2016-06-22 20:39:07 +02:00
|
|
|
/**
|
2017-04-13 16:12:03 +02:00
|
|
|
* Refresh the layout of a container
|
|
|
|
* @param cont pointer to an object which layout should be refreshed
|
2016-06-22 20:39:07 +02:00
|
|
|
*/
|
2017-04-13 16:12:03 +02:00
|
|
|
static void lv_cont_refr_layout(lv_obj_t * cont)
|
2016-06-22 20:39:07 +02:00
|
|
|
{
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_layout_t type = lv_cont_get_layout(cont);
|
|
|
|
|
|
|
|
/*'cont' has to be at least 1 child*/
|
|
|
|
if(lv_obj_get_child(cont, NULL) == NULL) return;
|
|
|
|
|
|
|
|
if(type == LV_LAYOUT_OFF) return;
|
|
|
|
|
|
|
|
if(type == LV_LAYOUT_CENTER) {
|
|
|
|
lv_cont_layout_center(cont);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(type == LV_LAYOUT_COLUMN_LEFT || type == LV_LAYOUT_COLUMN_MID || type == LV_LAYOUT_COLUMN_RIGHT) {
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_cont_layout_col(cont);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(type == LV_LAYOUT_ROW_TOP || type == LV_LAYOUT_ROW_MID || type == LV_LAYOUT_ROW_BOTTOM) {
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_cont_layout_row(cont);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(type == LV_LAYOUT_PRETTY_MID || type == LV_LAYOUT_PRETTY_TOP || type == LV_LAYOUT_PRETTY_BOTTOM) {
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_cont_layout_pretty(cont);
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(type == LV_LAYOUT_GRID) {
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_cont_layout_grid(cont);
|
|
|
|
}
|
2016-06-22 20:39:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle column type layouts
|
2017-04-13 16:12:03 +02:00
|
|
|
* @param cont pointer to an object which layout should be handled
|
2016-06-22 20:39:07 +02:00
|
|
|
*/
|
2017-04-13 16:12:03 +02:00
|
|
|
static void lv_cont_layout_col(lv_obj_t * cont)
|
2016-06-22 20:39:07 +02:00
|
|
|
{
|
2020-02-02 14:09:19 +01:00
|
|
|
lv_coord_t left = lv_obj_get_style_pad_left(cont, LV_CONT_PART_MAIN);
|
|
|
|
lv_coord_t right = lv_obj_get_style_pad_right(cont, LV_CONT_PART_MAIN);
|
|
|
|
lv_coord_t top = lv_obj_get_style_pad_top(cont, LV_CONT_PART_MAIN);
|
|
|
|
lv_coord_t inner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN);
|
2019-12-17 09:20:40 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_layout_t type = lv_cont_get_layout(cont);
|
|
|
|
lv_obj_t * child;
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Adjust margin and get the alignment type*/
|
|
|
|
lv_align_t align;
|
|
|
|
lv_coord_t hpad_corr;
|
2016-10-07 11:15:46 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
switch(type) {
|
2020-02-14 13:38:48 +01:00
|
|
|
case LV_LAYOUT_COLUMN_LEFT:
|
2019-12-17 09:20:40 +01:00
|
|
|
hpad_corr = left;
|
2019-04-04 07:15:40 +02:00
|
|
|
align = LV_ALIGN_IN_TOP_LEFT;
|
2018-06-19 09:49:58 +02:00
|
|
|
break;
|
2020-02-14 13:38:48 +01:00
|
|
|
case LV_LAYOUT_COLUMN_MID:
|
2018-06-19 09:49:58 +02:00
|
|
|
hpad_corr = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
align = LV_ALIGN_IN_TOP_MID;
|
2018-06-19 09:49:58 +02:00
|
|
|
break;
|
2020-02-14 13:38:48 +01:00
|
|
|
case LV_LAYOUT_COLUMN_RIGHT:
|
2019-12-17 09:20:40 +01:00
|
|
|
hpad_corr = -right;
|
2019-04-04 07:15:40 +02:00
|
|
|
align = LV_ALIGN_IN_TOP_RIGHT;
|
2018-06-19 09:49:58 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
hpad_corr = 0;
|
2019-04-04 07:15:40 +02:00
|
|
|
align = LV_ALIGN_IN_TOP_LEFT;
|
2018-06-19 09:49:58 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable child change action because the children will be moved a lot
|
|
|
|
* an unnecessary child change signals could be sent*/
|
2020-02-14 22:04:00 +01:00
|
|
|
lv_obj_add_protect(cont, LV_PROTECT_CHILD_CHG);
|
2018-06-19 09:49:58 +02:00
|
|
|
/* Align the children */
|
2019-12-17 09:20:40 +01:00
|
|
|
lv_coord_t last_cord = top;
|
2020-02-26 19:48:27 +01:00
|
|
|
LV_LL_READ_BACK(cont->child_ll, child) {
|
2019-06-06 06:05:40 +02:00
|
|
|
if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue;
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_style_int_t mtop = lv_obj_get_style_margin_top(child, LV_OBJ_PART_MAIN);
|
|
|
|
lv_style_int_t mbottom = lv_obj_get_style_margin_top(child, LV_OBJ_PART_MAIN);
|
|
|
|
lv_style_int_t mleft = lv_obj_get_style_margin_left(child, LV_OBJ_PART_MAIN);
|
|
|
|
lv_obj_align(child, cont, align, hpad_corr + mleft, last_cord + mtop);
|
|
|
|
last_cord += lv_obj_get_height(child) + inner + mtop + mbottom;
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG);
|
2016-06-22 20:39:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle row type layouts
|
2017-04-13 16:12:03 +02:00
|
|
|
* @param cont pointer to an object which layout should be handled
|
2016-06-22 20:39:07 +02:00
|
|
|
*/
|
2017-04-13 16:12:03 +02:00
|
|
|
static void lv_cont_layout_row(lv_obj_t * cont)
|
2016-06-22 20:39:07 +02:00
|
|
|
{
|
2019-12-17 09:20:40 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_layout_t type = lv_cont_get_layout(cont);
|
|
|
|
lv_obj_t * child;
|
|
|
|
|
|
|
|
/*Adjust margin and get the alignment type*/
|
|
|
|
lv_align_t align;
|
2019-03-13 23:58:33 +01:00
|
|
|
lv_coord_t vpad_corr;
|
2019-10-14 15:25:40 +02:00
|
|
|
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(cont);
|
2018-06-19 09:49:58 +02:00
|
|
|
switch(type) {
|
2020-02-14 13:38:48 +01:00
|
|
|
case LV_LAYOUT_ROW_TOP:
|
2020-02-02 14:09:19 +01:00
|
|
|
vpad_corr = lv_obj_get_style_pad_top(cont, LV_CONT_PART_MAIN);
|
2019-10-14 15:25:40 +02:00
|
|
|
align = base_dir == LV_BIDI_DIR_RTL ? LV_ALIGN_IN_TOP_RIGHT : LV_ALIGN_IN_TOP_LEFT;
|
2018-06-19 09:49:58 +02:00
|
|
|
break;
|
2020-02-14 13:38:48 +01:00
|
|
|
case LV_LAYOUT_ROW_MID:
|
2018-06-19 09:49:58 +02:00
|
|
|
vpad_corr = 0;
|
2020-02-26 19:48:27 +01:00
|
|
|
align = base_dir == LV_BIDI_DIR_RTL ? LV_ALIGN_IN_RIGHT_MID : LV_ALIGN_IN_LEFT_MID;
|
2018-06-19 09:49:58 +02:00
|
|
|
break;
|
2020-02-14 13:38:48 +01:00
|
|
|
case LV_LAYOUT_ROW_BOTTOM:
|
2020-02-02 14:09:19 +01:00
|
|
|
vpad_corr = -lv_obj_get_style_pad_bottom(cont, LV_CONT_PART_MAIN);
|
2020-02-26 19:48:27 +01:00
|
|
|
align = base_dir == LV_BIDI_DIR_RTL ? LV_ALIGN_IN_BOTTOM_RIGHT : LV_ALIGN_IN_BOTTOM_LEFT;
|
2018-06-19 09:49:58 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
vpad_corr = 0;
|
2019-10-14 15:25:40 +02:00
|
|
|
align = base_dir == LV_BIDI_DIR_RTL ? LV_ALIGN_IN_TOP_RIGHT : LV_ALIGN_IN_TOP_LEFT;
|
2018-06-19 09:49:58 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable child change action because the children will be moved a lot
|
|
|
|
* an unnecessary child change signals could be sent*/
|
2020-02-14 22:04:00 +01:00
|
|
|
lv_obj_add_protect(cont, LV_PROTECT_CHILD_CHG);
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/* Align the children */
|
2019-10-14 15:25:40 +02:00
|
|
|
lv_coord_t last_cord;
|
2020-02-02 14:09:19 +01:00
|
|
|
if(base_dir == LV_BIDI_DIR_RTL) last_cord = lv_obj_get_style_pad_right(cont, LV_CONT_PART_MAIN);
|
|
|
|
else last_cord = lv_obj_get_style_pad_left(cont, LV_CONT_PART_MAIN);
|
2019-12-17 09:20:40 +01:00
|
|
|
|
2020-02-02 14:09:19 +01:00
|
|
|
lv_coord_t inner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN);
|
2019-10-14 15:25:40 +02:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
LV_LL_READ_BACK(cont->child_ll, child) {
|
2019-06-06 06:05:40 +02:00
|
|
|
if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue;
|
2016-07-12 01:16:27 +02:00
|
|
|
|
2019-10-14 15:25:40 +02:00
|
|
|
if(base_dir == LV_BIDI_DIR_RTL) lv_obj_align(child, cont, align, -last_cord, vpad_corr);
|
|
|
|
else lv_obj_align(child, cont, align, last_cord, vpad_corr);
|
|
|
|
|
2019-12-17 09:20:40 +01:00
|
|
|
last_cord += lv_obj_get_width(child) + inner;
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG);
|
2016-06-22 20:39:07 +02:00
|
|
|
}
|
|
|
|
|
2016-09-27 13:43:01 +02:00
|
|
|
/**
|
|
|
|
* Handle the center layout
|
2017-04-13 16:12:03 +02:00
|
|
|
* @param cont pointer to an object which layout should be handled
|
2016-09-27 13:43:01 +02:00
|
|
|
*/
|
2017-04-13 16:12:03 +02:00
|
|
|
static void lv_cont_layout_center(lv_obj_t * cont)
|
2016-06-22 20:39:07 +02:00
|
|
|
{
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_t * child;
|
2019-04-11 19:59:55 +08:00
|
|
|
uint32_t obj_num = 0;
|
|
|
|
lv_coord_t h_tot = 0;
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2020-02-02 14:09:19 +01:00
|
|
|
lv_coord_t inner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN);
|
2020-02-26 19:48:27 +01:00
|
|
|
LV_LL_READ(cont->child_ll, child) {
|
2019-06-06 06:05:40 +02:00
|
|
|
if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue;
|
2019-12-17 09:20:40 +01:00
|
|
|
h_tot += lv_obj_get_height(child) + inner;
|
2019-04-04 07:15:40 +02:00
|
|
|
obj_num++;
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
if(obj_num == 0) return;
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2019-12-17 09:20:40 +01:00
|
|
|
h_tot -= inner;
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/* Disable child change action because the children will be moved a lot
|
|
|
|
* an unnecessary child change signals could be sent*/
|
2020-02-14 22:04:00 +01:00
|
|
|
lv_obj_add_protect(cont, LV_PROTECT_CHILD_CHG);
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/* Align the children */
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_coord_t last_cord = -(h_tot / 2);
|
2020-02-26 19:48:27 +01:00
|
|
|
LV_LL_READ_BACK(cont->child_ll, child) {
|
2019-06-06 06:05:40 +02:00
|
|
|
if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue;
|
2016-07-12 01:16:27 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_align(child, cont, LV_ALIGN_CENTER, 0, last_cord + lv_obj_get_height(child) / 2);
|
2019-12-17 09:20:40 +01:00
|
|
|
last_cord += lv_obj_get_height(child) + inner;
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG);
|
2016-06-22 20:39:07 +02:00
|
|
|
}
|
|
|
|
|
2016-09-27 13:43:01 +02:00
|
|
|
/**
|
2016-12-17 10:50:28 +01:00
|
|
|
* Handle the pretty layout. Put as many object as possible in row
|
2016-09-27 13:43:01 +02:00
|
|
|
* then begin a new row
|
2017-04-13 16:12:03 +02:00
|
|
|
* @param cont pointer to an object which layout should be handled
|
2016-09-27 13:43:01 +02:00
|
|
|
*/
|
2017-04-13 16:12:03 +02:00
|
|
|
static void lv_cont_layout_pretty(lv_obj_t * cont)
|
2016-09-27 13:43:01 +02:00
|
|
|
{
|
2020-02-19 06:34:35 +01:00
|
|
|
lv_layout_t type = lv_cont_get_layout(cont);
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_t * child_rs; /* Row starter child */
|
|
|
|
lv_obj_t * child_rc; /* Row closer child */
|
|
|
|
lv_obj_t * child_tmp; /* Temporary child */
|
2019-04-11 19:59:55 +08:00
|
|
|
lv_coord_t w_obj = lv_obj_get_width(cont);
|
2020-02-02 14:09:19 +01:00
|
|
|
lv_coord_t act_y = lv_obj_get_style_pad_top(cont, LV_CONT_PART_MAIN);
|
2018-06-19 09:49:58 +02:00
|
|
|
/* Disable child change action because the children will be moved a lot
|
|
|
|
* an unnecessary child change signals could be sent*/
|
|
|
|
|
|
|
|
child_rs = lv_ll_get_tail(&cont->child_ll); /*Set the row starter child*/
|
2019-04-04 07:15:40 +02:00
|
|
|
if(child_rs == NULL) return; /*Return if no child*/
|
2016-09-27 13:43:01 +02:00
|
|
|
|
2020-02-14 22:04:00 +01:00
|
|
|
lv_obj_add_protect(cont, LV_PROTECT_CHILD_CHG);
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_coord_t pleft = lv_obj_get_style_pad_left(cont, LV_CONT_PART_MAIN);
|
|
|
|
lv_coord_t pright = lv_obj_get_style_pad_right(cont, LV_CONT_PART_MAIN);
|
|
|
|
lv_coord_t pinner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN);
|
2016-09-27 13:43:01 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
child_rc = child_rs; /*Initially the the row starter and closer is the same*/
|
|
|
|
while(child_rs != NULL) {
|
|
|
|
lv_coord_t h_row = 0;
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_coord_t w_row = pleft + pright; /*The width is at least the left+right pad*/
|
2018-06-19 09:49:58 +02:00
|
|
|
uint32_t obj_num = 0;
|
|
|
|
|
|
|
|
/*Find the row closer object and collect some data*/
|
|
|
|
do {
|
2019-06-06 06:05:40 +02:00
|
|
|
if(lv_obj_get_hidden(child_rc) == false && lv_obj_is_protected(child_rc, LV_PROTECT_POS) == false) {
|
2018-06-19 09:49:58 +02:00
|
|
|
/*If this object is already not fit then break*/
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_coord_t w = lv_obj_get_width(child_rc);
|
|
|
|
w += lv_obj_get_style_margin_left(child_rc, LV_OBJ_PART_MAIN);
|
|
|
|
w += lv_obj_get_style_margin_right(child_rc, LV_OBJ_PART_MAIN);
|
|
|
|
if(w_row + w > w_obj) {
|
2019-04-04 07:15:40 +02:00
|
|
|
/*Step back one child because the last already not fit, so the previous is the
|
|
|
|
* closer*/
|
|
|
|
if(child_rc != NULL && obj_num != 0) {
|
2018-06-19 09:49:58 +02:00
|
|
|
child_rc = lv_ll_get_next(&cont->child_ll, child_rc);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-04-08 11:12:06 +02:00
|
|
|
w_row += w + pinner; /*Add the object width + inner padding*/
|
|
|
|
|
|
|
|
lv_coord_t h = lv_obj_get_height(child_rc);
|
|
|
|
h += lv_obj_get_style_margin_top(child_rc, LV_OBJ_PART_MAIN);
|
|
|
|
h += lv_obj_get_style_margin_bottom(child_rc, LV_OBJ_PART_MAIN);
|
|
|
|
h_row = LV_MATH_MAX(h_row, h); /*Search the highest object*/
|
2019-04-04 07:15:40 +02:00
|
|
|
obj_num++;
|
|
|
|
if(lv_obj_is_protected(child_rc, LV_PROTECT_FOLLOW))
|
|
|
|
break; /*If can not be followed by an other object then break here*/
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
|
|
|
child_rc = lv_ll_get_prev(&cont->child_ll, child_rc); /*Load the next object*/
|
2019-04-04 07:15:40 +02:00
|
|
|
if(obj_num == 0)
|
|
|
|
child_rs = child_rc; /*If the first object was hidden (or too long) then set the
|
|
|
|
next as first */
|
2018-06-19 09:49:58 +02:00
|
|
|
} while(child_rc != NULL);
|
|
|
|
|
2020-02-19 06:34:35 +01:00
|
|
|
/*If the object is too long then align it to the middle*/
|
2018-06-19 09:49:58 +02:00
|
|
|
if(obj_num == 0) {
|
|
|
|
if(child_rc != NULL) {
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_style_int_t mtop = lv_obj_get_style_margin_top(child_rc, LV_OBJ_PART_MAIN);
|
|
|
|
|
|
|
|
lv_obj_align(child_rc, cont, LV_ALIGN_IN_TOP_MID, 0, act_y + mtop);
|
2019-06-06 06:05:40 +02:00
|
|
|
h_row = lv_obj_get_height(child_rc); /*Not set previously because of the early break*/
|
2020-04-08 11:12:06 +02:00
|
|
|
h_row += mtop;
|
|
|
|
h_row += lv_obj_get_style_margin_bottom(child_rc, LV_OBJ_PART_MAIN);
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*If there is only one object in the row then align it to the middle*/
|
|
|
|
else if(obj_num == 1) {
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_obj_align(child_rs, cont, LV_ALIGN_IN_TOP_MID,
|
2020-04-08 20:54:02 +02:00
|
|
|
0,
|
2020-04-08 11:12:06 +02:00
|
|
|
act_y + lv_obj_get_style_margin_top(child_rs, LV_OBJ_PART_MAIN));
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2018-02-23 13:56:04 +01:00
|
|
|
/*If there are two object in the row then align them proportionally*/
|
2020-04-08 20:54:02 +02:00
|
|
|
else if(obj_num == 2 && 0) {
|
2017-07-27 13:45:37 +02:00
|
|
|
lv_obj_t * obj1 = child_rs;
|
2017-11-24 17:48:47 +01:00
|
|
|
lv_obj_t * obj2 = lv_ll_get_prev(&cont->child_ll, child_rs);
|
2019-04-04 07:15:40 +02:00
|
|
|
w_row = lv_obj_get_width(obj1) + lv_obj_get_width(obj2);
|
|
|
|
lv_coord_t pad = (w_obj - w_row) / 3;
|
2020-04-08 11:12:06 +02:00
|
|
|
|
2020-02-19 06:34:35 +01:00
|
|
|
switch(type) {
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_LAYOUT_PRETTY_TOP:
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT,
|
|
|
|
pad + lv_obj_get_style_margin_left(obj1, LV_OBJ_PART_MAIN),
|
|
|
|
act_y + lv_obj_get_style_margin_top(obj1, LV_OBJ_PART_MAIN));
|
|
|
|
lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT,
|
|
|
|
-pad - lv_obj_get_style_margin_right(obj2, LV_OBJ_PART_MAIN),
|
|
|
|
act_y + lv_obj_get_style_margin_top(obj2, LV_OBJ_PART_MAIN));
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
case LV_LAYOUT_PRETTY_MID:
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT,
|
|
|
|
pad + lv_obj_get_style_margin_left(obj1, LV_OBJ_PART_MAIN),
|
|
|
|
act_y + (h_row - lv_obj_get_height(obj1)) / 2 + lv_obj_get_style_margin_top(obj1, LV_OBJ_PART_MAIN));
|
|
|
|
lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT,
|
|
|
|
-pad - lv_obj_get_style_margin_right(obj2, LV_OBJ_PART_MAIN),
|
|
|
|
act_y + (h_row - lv_obj_get_height(obj2)) / 2 + lv_obj_get_style_margin_top(obj2, LV_OBJ_PART_MAIN));
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
case LV_LAYOUT_PRETTY_BOTTOM:
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT,
|
|
|
|
pad + lv_obj_get_style_margin_left(obj1, LV_OBJ_PART_MAIN),
|
|
|
|
act_y + h_row - lv_obj_get_height(obj1) - lv_obj_get_style_margin_bottom(obj1, LV_OBJ_PART_MAIN));
|
|
|
|
lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT,
|
|
|
|
-pad - lv_obj_get_style_margin_right(obj2, LV_OBJ_PART_MAIN),
|
|
|
|
act_y + h_row - lv_obj_get_height(obj2) - lv_obj_get_style_margin_bottom(obj2, LV_OBJ_PART_MAIN));
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2020-02-19 06:34:35 +01:00
|
|
|
}
|
2017-07-27 13:45:37 +02:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
/* Align the children (from child_rs to child_rc)*/
|
|
|
|
else {
|
2020-04-08 11:12:06 +02:00
|
|
|
w_row -= pinner * obj_num;
|
|
|
|
lv_coord_t new_pinner = (w_obj - w_row) / (obj_num - 1);
|
|
|
|
lv_coord_t act_x = pleft; /*x init*/
|
2019-04-04 07:15:40 +02:00
|
|
|
child_tmp = child_rs;
|
2018-06-19 09:49:58 +02:00
|
|
|
while(child_tmp != NULL) {
|
2019-06-06 06:05:40 +02:00
|
|
|
if(lv_obj_get_hidden(child_tmp) == false && lv_obj_is_protected(child_tmp, LV_PROTECT_POS) == false) {
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_coord_t mleft = lv_obj_get_style_margin_left(child_tmp, LV_OBJ_PART_MAIN);
|
|
|
|
lv_coord_t mright = lv_obj_get_style_margin_right(child_tmp, LV_OBJ_PART_MAIN);
|
2020-02-19 06:34:35 +01:00
|
|
|
switch(type) {
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_LAYOUT_PRETTY_TOP:
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT,
|
|
|
|
act_x + mleft,
|
|
|
|
act_y + lv_obj_get_style_margin_top(child_tmp, LV_OBJ_PART_MAIN));
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
case LV_LAYOUT_PRETTY_MID:
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT,
|
|
|
|
act_x + mleft,
|
2020-02-26 19:48:27 +01:00
|
|
|
act_y + (h_row - lv_obj_get_height(child_tmp)) / 2);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case LV_LAYOUT_PRETTY_BOTTOM:
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT,
|
|
|
|
act_x + mleft,
|
|
|
|
act_y + h_row - lv_obj_get_height(child_tmp) - lv_obj_get_style_margin_bottom(child_tmp, LV_OBJ_PART_MAIN));
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2020-02-19 06:34:35 +01:00
|
|
|
}
|
|
|
|
|
2020-04-08 11:12:06 +02:00
|
|
|
act_x += lv_obj_get_width(child_tmp) + new_pinner + mleft + mright;
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
|
|
|
if(child_tmp == child_rc) break;
|
|
|
|
child_tmp = lv_ll_get_prev(&cont->child_ll, child_tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(child_rc == NULL) break;
|
2020-04-08 11:12:06 +02:00
|
|
|
act_y += pinner + h_row; /*y increment*/
|
2018-06-19 09:49:58 +02:00
|
|
|
child_rs = lv_ll_get_prev(&cont->child_ll, child_rc); /*Go to the next object*/
|
|
|
|
child_rc = child_rs;
|
|
|
|
}
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG);
|
2016-09-27 13:43:01 +02:00
|
|
|
}
|
|
|
|
|
2016-12-17 10:50:28 +01:00
|
|
|
/**
|
|
|
|
* Handle the grid layout. Align same-sized objects in a grid
|
2017-04-13 16:12:03 +02:00
|
|
|
* @param cont pointer to an object which layout should be handled
|
2016-12-17 10:50:28 +01:00
|
|
|
*/
|
2017-04-13 16:12:03 +02:00
|
|
|
static void lv_cont_layout_grid(lv_obj_t * cont)
|
2016-12-17 10:50:28 +01:00
|
|
|
{
|
2020-04-14 14:57:04 +02:00
|
|
|
|
2019-07-09 15:37:50 +02:00
|
|
|
lv_coord_t w_fit = lv_obj_get_width_fit(cont);
|
2019-04-11 19:59:55 +08:00
|
|
|
lv_coord_t h_obj = lv_obj_get_height(lv_obj_get_child(cont, NULL));
|
2020-02-02 14:09:19 +01:00
|
|
|
lv_coord_t inner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN);
|
2020-04-14 14:57:04 +02:00
|
|
|
lv_coord_t y_ofs = inner + lv_obj_get_height(lv_obj_get_child(cont, NULL));
|
2018-06-19 09:49:58 +02:00
|
|
|
|
|
|
|
/* Disable child change action because the children will be moved a lot
|
|
|
|
* an unnecessary child change signals could be sent*/
|
2020-02-14 22:04:00 +01:00
|
|
|
lv_obj_add_protect(cont, LV_PROTECT_CHILD_CHG);
|
2016-12-17 10:50:28 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/* Align the children */
|
2020-02-02 14:09:19 +01:00
|
|
|
lv_coord_t left = lv_obj_get_style_pad_left(cont, LV_CONT_PART_MAIN);
|
2019-12-17 09:20:40 +01:00
|
|
|
lv_coord_t act_x = left;
|
2020-02-02 14:09:19 +01:00
|
|
|
lv_coord_t act_y = lv_obj_get_style_pad_top(cont, LV_CONT_PART_MAIN);
|
2018-06-19 09:49:58 +02:00
|
|
|
uint16_t obj_cnt = 0;
|
2020-04-13 05:56:59 +02:00
|
|
|
lv_obj_t * child;
|
2020-02-26 19:48:27 +01:00
|
|
|
LV_LL_READ_BACK(cont->child_ll, child) {
|
2019-06-06 06:05:40 +02:00
|
|
|
if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue;
|
2020-04-13 05:56:59 +02:00
|
|
|
lv_coord_t obj_w = lv_obj_get_width(child);
|
2020-04-14 14:57:04 +02:00
|
|
|
if(act_x + inner + obj_w > w_fit) {
|
|
|
|
act_x = left;
|
2018-06-19 09:49:58 +02:00
|
|
|
act_y += y_ofs;
|
|
|
|
}
|
2020-04-13 05:56:59 +02:00
|
|
|
|
|
|
|
lv_obj_set_pos(child, act_x, act_y);
|
2020-04-14 14:57:04 +02:00
|
|
|
act_x += inner + obj_w;
|
2018-06-19 09:49:58 +02:00
|
|
|
}
|
2016-12-17 10:50:28 +01:00
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_clear_protect(cont, LV_PROTECT_CHILD_CHG);
|
2016-12-17 10:50:28 +01:00
|
|
|
}
|
|
|
|
|
2016-09-27 13:43:01 +02:00
|
|
|
/**
|
|
|
|
* Handle auto fit. Set the size of the object to involve all children.
|
2017-04-13 16:12:03 +02:00
|
|
|
* @param cont pointer to an object which size will be modified
|
2016-09-27 13:43:01 +02:00
|
|
|
*/
|
2017-04-13 16:12:03 +02:00
|
|
|
static void lv_cont_refr_autofit(lv_obj_t * cont)
|
2016-06-22 20:39:07 +02:00
|
|
|
{
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
if(ext->fit_left == LV_FIT_NONE && ext->fit_right == LV_FIT_NONE && ext->fit_top == LV_FIT_NONE &&
|
|
|
|
ext->fit_bottom == LV_FIT_NONE) {
|
2018-06-19 09:49:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_area_t tight_area;
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_area_t ori;
|
2019-03-09 05:51:33 +01:00
|
|
|
lv_obj_t * child_i;
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2019-04-11 19:59:55 +08:00
|
|
|
lv_obj_t * par = lv_obj_get_parent(cont);
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_area_t parent_area;
|
|
|
|
lv_area_copy(&parent_area, &par->coords);
|
|
|
|
parent_area.x1 += lv_obj_get_style_pad_left(par, LV_OBJ_PART_MAIN);
|
|
|
|
parent_area.x2 -= lv_obj_get_style_pad_right(par, LV_OBJ_PART_MAIN);
|
|
|
|
parent_area.y1 += lv_obj_get_style_pad_top(par, LV_OBJ_PART_MAIN);
|
|
|
|
parent_area.y2 -= lv_obj_get_style_pad_bottom(par, LV_OBJ_PART_MAIN);
|
2019-02-24 06:24:36 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Search the side coordinates of the children*/
|
|
|
|
lv_obj_get_coords(cont, &ori);
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_obj_get_coords(cont, &tight_area);
|
|
|
|
|
|
|
|
bool has_children = lv_ll_is_empty(&cont->child_ll) ? false : true;
|
|
|
|
|
|
|
|
if(has_children) {
|
|
|
|
tight_area.x1 = LV_COORD_MAX;
|
|
|
|
tight_area.y1 = LV_COORD_MAX;
|
|
|
|
tight_area.x2 = LV_COORD_MIN;
|
|
|
|
tight_area.y2 = LV_COORD_MIN;
|
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
LV_LL_READ(cont->child_ll, child_i) {
|
2019-03-09 05:51:33 +01:00
|
|
|
if(lv_obj_get_hidden(child_i) != false) continue;
|
2020-04-08 11:12:06 +02:00
|
|
|
lv_style_int_t mleft = lv_obj_get_style_margin_left(child_i, LV_OBJ_PART_MAIN);
|
|
|
|
lv_style_int_t mright = lv_obj_get_style_margin_right(child_i, LV_OBJ_PART_MAIN);
|
|
|
|
lv_style_int_t mtop = lv_obj_get_style_margin_top(child_i, LV_OBJ_PART_MAIN);
|
|
|
|
lv_style_int_t mbottom = lv_obj_get_style_margin_bottom(child_i, LV_OBJ_PART_MAIN);
|
|
|
|
tight_area.x1 = LV_MATH_MIN(tight_area.x1, child_i->coords.x1 - mleft);
|
|
|
|
tight_area.y1 = LV_MATH_MIN(tight_area.y1, child_i->coords.y1 - mtop);
|
|
|
|
tight_area.x2 = LV_MATH_MAX(tight_area.x2, child_i->coords.x2 + mright);
|
|
|
|
tight_area.y2 = LV_MATH_MAX(tight_area.y2, child_i->coords.y2 + mbottom);
|
2019-02-24 06:24:36 +01:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:09:19 +01:00
|
|
|
tight_area.x1 -= lv_obj_get_style_pad_left(cont, LV_CONT_PART_MAIN);
|
|
|
|
tight_area.x2 += lv_obj_get_style_pad_right(cont, LV_CONT_PART_MAIN);
|
|
|
|
tight_area.y1 -= lv_obj_get_style_pad_top(cont, LV_CONT_PART_MAIN);
|
|
|
|
tight_area.y2 += lv_obj_get_style_pad_bottom(cont, LV_CONT_PART_MAIN);
|
2016-06-22 20:39:07 +02:00
|
|
|
}
|
|
|
|
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_area_t new_area;
|
|
|
|
lv_area_copy(&new_area, &ori);
|
|
|
|
|
|
|
|
switch(ext->fit_left) {
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_FIT_TIGHT:
|
|
|
|
new_area.x1 = tight_area.x1;
|
|
|
|
break;
|
|
|
|
case LV_FIT_PARENT:
|
2020-04-08 11:12:06 +02:00
|
|
|
new_area.x1 = parent_area.x1;
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
case LV_FIT_MAX:
|
2020-04-08 11:12:06 +02:00
|
|
|
new_area.x1 = has_children ? LV_MATH_MIN(tight_area.x1, parent_area.x1) : parent_area.x1;
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2019-02-24 06:24:36 +01:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2019-02-24 06:24:36 +01:00
|
|
|
switch(ext->fit_right) {
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_FIT_TIGHT:
|
|
|
|
new_area.x2 = tight_area.x2;
|
|
|
|
break;
|
|
|
|
case LV_FIT_PARENT:
|
2020-04-08 11:12:06 +02:00
|
|
|
new_area.x2 = parent_area.x2;
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
case LV_FIT_MAX:
|
2020-04-08 11:12:06 +02:00
|
|
|
new_area.x2 = has_children ? LV_MATH_MAX(tight_area.x2, parent_area.x2) : parent_area.x2;
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2019-02-24 06:24:36 +01:00
|
|
|
}
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2019-02-24 06:24:36 +01:00
|
|
|
switch(ext->fit_top) {
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_FIT_TIGHT:
|
|
|
|
new_area.y1 = tight_area.y1;
|
|
|
|
break;
|
|
|
|
case LV_FIT_PARENT:
|
2020-04-08 11:12:06 +02:00
|
|
|
new_area.y1 = parent_area.y1;
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
case LV_FIT_MAX:
|
2020-04-08 11:12:06 +02:00
|
|
|
new_area.y1 = has_children ? LV_MATH_MIN(tight_area.y1, parent_area.y1) : parent_area.y1;
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2019-02-24 06:24:36 +01:00
|
|
|
}
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2019-02-24 06:24:36 +01:00
|
|
|
switch(ext->fit_bottom) {
|
2020-02-26 19:48:27 +01:00
|
|
|
case LV_FIT_TIGHT:
|
|
|
|
new_area.y2 = tight_area.y2;
|
|
|
|
break;
|
|
|
|
case LV_FIT_PARENT:
|
2020-04-08 11:12:06 +02:00
|
|
|
new_area.y2 = parent_area.y2;
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
case LV_FIT_MAX:
|
2020-04-08 11:12:06 +02:00
|
|
|
new_area.y2 = has_children ? LV_MATH_MAX(tight_area.y2, parent_area.y2) : parent_area.y2;
|
2020-02-26 19:48:27 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2019-02-24 06:24:36 +01:00
|
|
|
}
|
2016-06-22 20:39:07 +02:00
|
|
|
|
2019-02-24 06:24:36 +01:00
|
|
|
/*Do nothing if the coordinates are not changed*/
|
2019-06-06 06:05:40 +02:00
|
|
|
if(cont->coords.x1 != new_area.x1 || cont->coords.y1 != new_area.y1 || cont->coords.x2 != new_area.x2 ||
|
|
|
|
cont->coords.y2 != new_area.y2) {
|
2019-02-24 06:24:36 +01:00
|
|
|
|
|
|
|
lv_obj_invalidate(cont);
|
|
|
|
lv_area_copy(&cont->coords, &new_area);
|
|
|
|
lv_obj_invalidate(cont);
|
|
|
|
|
|
|
|
/*Notify the object about its new coordinates*/
|
2020-01-05 01:16:13 +01:00
|
|
|
cont->signal_cb(cont, LV_SIGNAL_COORD_CHG, &ori);
|
2019-02-24 06:24:36 +01:00
|
|
|
|
|
|
|
/*Inform the parent about the new coordinates*/
|
2019-02-26 09:25:46 +01:00
|
|
|
par->signal_cb(par, LV_SIGNAL_CHILD_CHG, cont);
|
2019-02-24 07:06:22 +01:00
|
|
|
|
2019-06-21 15:26:28 +02:00
|
|
|
if(lv_obj_get_auto_realign(cont)) {
|
|
|
|
lv_obj_realign(cont);
|
|
|
|
}
|
|
|
|
|
2019-02-24 07:06:22 +01:00
|
|
|
/*Tell the children the parent's size has changed*/
|
2020-01-20 16:11:38 +01:00
|
|
|
LV_LL_READ(cont->child_ll, child_i) {
|
|
|
|
child_i->signal_cb(child_i, LV_SIGNAL_PARENT_SIZE_CHG, &ori);
|
2019-02-24 07:06:22 +01:00
|
|
|
}
|
2016-06-22 20:39:07 +02:00
|
|
|
}
|
|
|
|
}
|
2016-06-08 07:25:08 +02:00
|
|
|
|
|
|
|
#endif
|