feat(style): store layout and position coordinates as style properties

related to #2152
This commit is contained in:
Gabor Kiss-Vamosi
2021-03-23 20:51:39 +01:00
parent 7cc3ed51bf
commit b7becbbb22
71 changed files with 1247 additions and 882 deletions

View File

@@ -1,5 +1,5 @@
#include "../../lvgl.h" #include "../../lvgl.h"
#if LV_BUILD_EXAMPLES #if LV_BUILD_EXAMPLES && LV_USE_BTN
static void btn_event_cb(lv_obj_t * btn, lv_event_t event) static void btn_event_cb(lv_obj_t * btn, lv_event_t event)
{ {

View File

@@ -6,25 +6,17 @@
*/ */
void lv_example_flex_1(void) void lv_example_flex_1(void)
{ {
static lv_flex_t flex_row;
lv_flex_init(&flex_row);
lv_flex_set_flow(&flex_row, LV_FLEX_FLOW_ROW);
static lv_flex_t flex_col;
lv_flex_init(&flex_col);
lv_flex_set_flow(&flex_col, LV_FLEX_FLOW_COLUMN);
/*Create a container with ROW flex direction*/ /*Create a container with ROW flex direction*/
lv_obj_t * cont_row = lv_obj_create(lv_scr_act(), NULL); lv_obj_t * cont_row = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont_row, 300, 75); lv_obj_set_size(cont_row, 300, 75);
lv_obj_align(cont_row, NULL, LV_ALIGN_IN_TOP_MID, 0, 5); lv_obj_align(cont_row, NULL, LV_ALIGN_IN_TOP_MID, 0, 5);
lv_obj_set_layout(cont_row, &flex_row); lv_obj_set_flex_flow(cont_row, LV_FLEX_FLOW_ROW);
/*Create a container with COLUMN flex direction*/ /*Create a container with COLUMN flex direction*/
lv_obj_t * cont_col = lv_obj_create(lv_scr_act(), NULL); lv_obj_t * cont_col = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont_col, 200, 150); lv_obj_set_size(cont_col, 200, 150);
lv_obj_align(cont_col, cont_row, LV_ALIGN_OUT_BOTTOM_MID, 0, 5); lv_obj_align(cont_col, cont_row, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
lv_obj_set_layout(cont_col, &flex_col); lv_obj_set_flex_flow(cont_col, LV_FLEX_FLOW_COLUMN);
uint32_t i; uint32_t i;
for(i = 0; i < 10; i++) { for(i = 0; i < 10; i++) {

View File

@@ -6,15 +6,16 @@
*/ */
void lv_example_flex_2(void) void lv_example_flex_2(void)
{ {
static lv_flex_t flex_row_wrap; static lv_style_t style;
lv_flex_init(&flex_row_wrap); lv_style_init(&style);
lv_flex_set_flow(&flex_row_wrap, LV_FLEX_FLOW_ROW_WRAP); lv_style_set_flex_flow(&style, LV_FLEX_FLOW_ROW_WRAP);
lv_flex_set_place(&flex_row_wrap, LV_FLEX_PLACE_SPACE_EVENLY, LV_FLEX_PLACE_START, LV_FLEX_PLACE_START); lv_style_set_flex_main_place(&style, LV_FLEX_PLACE_SPACE_EVENLY);
lv_style_set_layout(&style, LV_LAYOUT_FLEX);
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont, 300, 220); lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &flex_row_wrap); lv_obj_add_style(cont, LV_PART_MAIN, LV_STATE_DEFAULT, &style);
uint32_t i; uint32_t i;
for(i = 0; i < 8; i++) { for(i = 0; i < 8; i++) {

View File

@@ -2,21 +2,21 @@
#if LV_USE_FLEX && LV_BUILD_EXAMPLES #if LV_USE_FLEX && LV_BUILD_EXAMPLES
/** /**
* Use a built in flex layout and demonstrate flex grow. * Demonstrate flex grow.
*/ */
void lv_example_flex_3(void) void lv_example_flex_3(void)
{ {
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont, 300, 220); lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &lv_flex_row_nowrap); lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW);
lv_obj_t * obj; lv_obj_t * obj;
obj = lv_obj_create(cont, NULL); obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, 20, 20); /*Fix size*/ lv_obj_set_size(obj, 40, 40); /*Fix size*/
obj = lv_obj_create(cont, NULL); obj = lv_obj_create(cont, NULL);
lv_obj_set_height(obj, 30); lv_obj_set_height(obj, 40);
lv_obj_set_flex_grow(obj, 1); /*1 portion from the free space*/ lv_obj_set_flex_grow(obj, 1); /*1 portion from the free space*/
obj = lv_obj_create(cont, NULL); obj = lv_obj_create(cont, NULL);
@@ -24,7 +24,7 @@ void lv_example_flex_3(void)
lv_obj_set_flex_grow(obj, 2); /*2 portion from the free space*/ lv_obj_set_flex_grow(obj, 2); /*2 portion from the free space*/
obj = lv_obj_create(cont, NULL); obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, 20, 20); /*Fix size. It is flushed to the right by the "grow" items*/ lv_obj_set_size(obj, 40, 40); /*Fix size. It is flushed to the right by the "grow" items*/
} }
#endif #endif

View File

@@ -7,19 +7,15 @@
void lv_example_flex_4(void) void lv_example_flex_4(void)
{ {
static lv_flex_t flex_col_rev;
lv_flex_init(&flex_col_rev);
lv_flex_set_flow(&flex_col_rev, LV_FLEX_FLOW_COLUMN_WRAP_REVERSE);
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont, 300, 220); lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &flex_col_rev); lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN_REVERSE);
uint32_t i; uint32_t i;
for(i = 0; i < 6; i++) { for(i = 0; i < 6; i++) {
lv_obj_t * obj = lv_obj_create(cont, NULL); lv_obj_t * obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, 100, 30); lv_obj_set_size(obj, 100, 50);
lv_obj_t * label = lv_label_create(obj, NULL); lv_obj_t * label = lv_label_create(obj, NULL);
lv_label_set_text_fmt(label, "Item: %d", i); lv_label_set_text_fmt(label, "Item: %d", i);

View File

@@ -19,7 +19,7 @@ void lv_example_flex_5(void)
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont, 300, 220); lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &lv_flex_row_wrap); lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW_WRAP);
uint32_t i; uint32_t i;
for(i = 0; i < 9; i++) { for(i = 0; i < 9; i++) {

View File

@@ -11,7 +11,7 @@ void lv_example_flex_6(void)
lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL); lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL);
lv_obj_set_size(cont, 300, 220); lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &lv_flex_column_center); lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW_WRAP);
uint32_t i; uint32_t i;
for(i = 0; i < 20; i++) { for(i = 0; i < 20; i++) {

View File

@@ -6,18 +6,16 @@
*/ */
void lv_example_grid_1(void) void lv_example_grid_1(void)
{ {
static lv_coord_t col_dsc[3] = {70, 70, 70}; static lv_coord_t col_dsc[] = {70, 70, 70, LV_COORD_MAX};
static lv_coord_t row_dsc[3] = {50, 50, 50}; static lv_coord_t row_dsc[] = {50, 50, 50, LV_COORD_MAX};
static lv_grid_t grid;
lv_grid_init(&grid);
lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
/*Create a container with grid*/ /*Create a container with grid*/
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_style_grid_column_template(cont, LV_PART_MAIN, LV_STATE_DEFAULT, col_dsc);
lv_obj_set_style_grid_row_template(cont, LV_PART_MAIN, LV_STATE_DEFAULT, row_dsc);
lv_obj_set_size(cont, 300, 220); lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &grid); lv_obj_set_layout(cont, LV_LAYOUT_GRID);
lv_obj_t * label; lv_obj_t * label;
lv_obj_t * obj; lv_obj_t * obj;

View File

@@ -7,18 +7,14 @@
*/ */
void lv_example_grid_2(void) void lv_example_grid_2(void)
{ {
static lv_coord_t col_dsc[3] = {70, 70, 70}; static lv_coord_t col_dsc[] = {70, 70, 70, LV_GRID_TEMPLATE_LAST};
static lv_coord_t row_dsc[3] = {50, 50, 50}; static lv_coord_t row_dsc[] = {50, 50, 50, LV_GRID_TEMPLATE_LAST};
static lv_grid_t grid;
lv_grid_init(&grid);
lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
/*Create a container with grid*/ /*Create a container with grid*/
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_grid_template(cont, col_dsc, row_dsc);
lv_obj_set_size(cont, 300, 220); lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &grid);
lv_obj_t * label; lv_obj_t * label;
lv_obj_t * obj; lv_obj_t * obj;

View File

@@ -9,22 +9,18 @@ void lv_example_grid_3(void)
/*Column 1: fix width 60 px /*Column 1: fix width 60 px
*Column 2: 1 unit from the remaining free space *Column 2: 1 unit from the remaining free space
*Column 3: 2 unit from the remaining free space*/ *Column 3: 2 unit from the remaining free space*/
static lv_coord_t col_dsc[3] = {60, LV_GRID_FR(1), LV_GRID_FR(2)}; static lv_coord_t col_dsc[] = {60, LV_GRID_FR(1), LV_GRID_FR(2), LV_GRID_TEMPLATE_LAST};
/*Row 1: fix width 60 px /*Row 1: fix width 60 px
*Row 2: 1 unit from the remaining free space *Row 2: 1 unit from the remaining free space
*Row 3: fix width 60 px*/ *Row 3: fix width 60 px*/
static lv_coord_t row_dsc[3] = {40, LV_GRID_FR(1), 40}; static lv_coord_t row_dsc[] = {40, LV_GRID_FR(1), 40, LV_GRID_TEMPLATE_LAST};
static lv_grid_t grid;
lv_grid_init(&grid);
lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
/*Create a container with grid*/ /*Create a container with grid*/
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont, 300, 220); lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &grid); lv_obj_set_grid_template(cont, col_dsc, row_dsc);
lv_obj_t * label; lv_obj_t * label;
lv_obj_t * obj; lv_obj_t * obj;

View File

@@ -6,21 +6,18 @@
*/ */
void lv_example_grid_4(void) void lv_example_grid_4(void)
{ {
static lv_coord_t col_dsc[3] = {60, 60, 60}; static lv_coord_t col_dsc[] = {60, 60, 60, LV_GRID_TEMPLATE_LAST};
static lv_coord_t row_dsc[3] = {40, 40, 40}; static lv_coord_t row_dsc[] = {40, 40, 40, LV_GRID_TEMPLATE_LAST};
static lv_grid_t grid;
lv_grid_init(&grid);
lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
/*Add space between the columns and move the rows to the bottom (end)*/ /*Add space between the columns and move the rows to the bottom (end)*/
lv_grid_set_place(&grid, LV_GRID_SPACE_BETWEEN, LV_GRID_END);
/*Create a container with grid*/ /*Create a container with grid*/
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_grid_place(cont, LV_GRID_SPACE_BETWEEN, LV_GRID_END);
lv_obj_set_grid_template(cont, col_dsc, row_dsc);
lv_obj_set_size(cont, 300, 220); lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &grid);
lv_obj_t * label; lv_obj_t * label;
lv_obj_t * obj; lv_obj_t * obj;

View File

@@ -18,18 +18,14 @@ void lv_example_grid_5(void)
{ {
/*60x60 cells*/ /*60x60 cells*/
static lv_coord_t col_dsc[3] = {60, 60, 60}; static lv_coord_t col_dsc[] = {60, 60, 60, LV_GRID_TEMPLATE_LAST};
static lv_coord_t row_dsc[3] = {40, 40, 40}; static lv_coord_t row_dsc[] = {40, 40, 40, LV_GRID_TEMPLATE_LAST};
static lv_grid_t grid;
lv_grid_init(&grid);
lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
/*Create a container with grid*/ /*Create a container with grid*/
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont, 300, 220); lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &grid); lv_obj_set_grid_template(cont, col_dsc, row_dsc);
lv_obj_t * label; lv_obj_t * label;
lv_obj_t * obj; lv_obj_t * obj;

View File

@@ -7,19 +7,15 @@
void lv_example_grid_6(void) void lv_example_grid_6(void)
{ {
static lv_coord_t col_dsc[3] = {60, 60, 60}; static lv_coord_t col_dsc[] = {60, 60, 60, LV_GRID_TEMPLATE_LAST};
static lv_coord_t row_dsc[3] = {40, 40, 40}; static lv_coord_t row_dsc[] = {40, 40, 40, LV_GRID_TEMPLATE_LAST};
static lv_grid_t grid;
lv_grid_init(&grid);
lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
/*Create a container with grid*/ /*Create a container with grid*/
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont, 300, 220); lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL); lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL);
lv_obj_set_layout(cont, &grid); lv_obj_set_grid_template(cont, col_dsc, row_dsc);
lv_obj_t * label; lv_obj_t * label;
lv_obj_t * obj; lv_obj_t * obj;

View File

@@ -1,5 +1,5 @@
#include "../../lvgl.h" #include "../../lvgl.h"
#if LV_BUILD_EXAMPLES #if LV_BUILD_EXAMPLES && LV_USE_FLEX
static void sw_event_cb(lv_obj_t * sw, lv_event_t e) static void sw_event_cb(lv_obj_t * sw, lv_event_t e)
{ {
@@ -19,7 +19,7 @@ void lv_example_scroll_2(void)
lv_obj_t * panel = lv_obj_create(lv_scr_act(), NULL); lv_obj_t * panel = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(panel, 280, 150); lv_obj_set_size(panel, 280, 150);
lv_obj_set_scroll_snap_x(panel, LV_SCROLL_SNAP_CENTER); lv_obj_set_scroll_snap_x(panel, LV_SCROLL_SNAP_CENTER);
lv_obj_set_layout(panel, &lv_flex_row_nowrap); lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW);
lv_obj_center(panel); lv_obj_center(panel);
uint32_t i; uint32_t i;

View File

@@ -19,7 +19,7 @@ void lv_example_bar_4(void)
lv_obj_set_size(bar, 260, 20); lv_obj_set_size(bar, 260, 20);
lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);
lv_bar_set_type(bar, LV_BAR_TYPE_RANGE); lv_bar_set_mode(bar, LV_BAR_MODE_RANGE);
lv_bar_set_value(bar, 90, LV_ANIM_OFF); lv_bar_set_value(bar, 90, LV_ANIM_OFF);
lv_bar_set_start_value(bar, 20, LV_ANIM_OFF); lv_bar_set_start_value(bar, 20, LV_ANIM_OFF);
} }

View File

@@ -15,21 +15,25 @@ static void event_handler(lv_obj_t * obj, lv_event_t event)
void lv_example_btn_1(void) void lv_example_btn_1(void)
{ {
lv_obj_t * label; lv_obj_t * label;
//
lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL); // lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_add_event_cb(btn1, event_handler, NULL); // lv_obj_add_event_cb(btn1, event_handler, NULL);
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -40); // lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -40);
//
label = lv_label_create(btn1, NULL); // label = lv_label_create(btn1, NULL);
lv_label_set_text(label, "Button"); // lv_label_set_text(label, "Button");
// lv_obj_center(label);
lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), NULL); lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_add_event_cb(btn2, event_handler, NULL); lv_obj_add_event_cb(btn2, event_handler, NULL);
lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 40); lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 40);
lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE); lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_height(btn2, LV_SIZE_CONTENT); // lv_obj_set_height(btn2, LV_SIZE_CONTENT);
label = lv_label_create(btn2, NULL); label = lv_label_create(btn2, NULL);
lv_label_set_text(label, "Toggle"); lv_label_set_text(label, "Toggle");
// lv_obj_update_layout(btn2);
// lv_obj_update_layout(cont);
} }
#endif #endif

View File

@@ -37,7 +37,6 @@ void lv_example_calendar_1(void)
lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3); lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3);
lv_obj_align(calendar, NULL, LV_ALIGN_CENTER, 0, -20);
#if LV_USE_CALENDAR_HEADER_DROPDOWN #if LV_USE_CALENDAR_HEADER_DROPDOWN
lv_calendar_header_dropdown_create(lv_scr_act(), calendar); lv_calendar_header_dropdown_create(lv_scr_act(), calendar);
#elif LV_USE_CALENDAR_HEADER_ARROW #elif LV_USE_CALENDAR_HEADER_ARROW

View File

@@ -12,12 +12,8 @@ static void event_handler(lv_obj_t * obj, lv_event_t event)
void lv_example_checkbox_1(void) void lv_example_checkbox_1(void)
{ {
static lv_flex_t flex_center; lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN);
lv_flex_init(&flex_center); lv_obj_set_flex_place(lv_scr_act(), LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_START, LV_FLEX_PLACE_CENTER);
lv_flex_set_flow(&flex_center, LV_FLEX_FLOW_COLUMN);
lv_flex_set_place(&flex_center, LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_START, LV_FLEX_PLACE_CENTER);
lv_obj_set_layout(lv_scr_act(), &flex_center);
lv_obj_t * cb; lv_obj_t * cb;
cb = lv_checkbox_create(lv_scr_act(), NULL); cb = lv_checkbox_create(lv_scr_act(), NULL);

View File

@@ -12,8 +12,20 @@ void lv_example_list_1(void)
{ {
/*Create a list*/ /*Create a list*/
list1 = lv_list_create(lv_scr_act()); list1 = lv_list_create(lv_scr_act());
lv_obj_set_size(list1, 180, 220);
lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);
uint32_t t = lv_tick_get();
int i;
for(i = 0; i < 3; i++) {
// lv_btn_create(lv_scr_act(), NULL);
lv_list_add_btn(list1, LV_SYMBOL_FILE, "New", event_handler);
}
printf("%d\n", t);
return;
/*Add buttons to the list*/ /*Add buttons to the list*/
lv_list_add_text(list1, "File"); lv_list_add_text(list1, "File");
lv_list_add_btn(list1, LV_SYMBOL_FILE, "New", event_handler); lv_list_add_btn(list1, LV_SYMBOL_FILE, "New", event_handler);

View File

@@ -14,7 +14,7 @@ void lv_example_slider_3(void)
slider = lv_slider_create(lv_scr_act(), NULL); slider = lv_slider_create(lv_scr_act(), NULL);
lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(slider, slider_event_cb, NULL); lv_obj_add_event_cb(slider, slider_event_cb, NULL);
lv_slider_set_type(slider, LV_SLIDER_TYPE_RANGE); lv_slider_set_mode(slider, LV_SLIDER_MODE_RANGE);
lv_slider_set_value(slider, 70, LV_ANIM_OFF); lv_slider_set_value(slider, 70, LV_ANIM_OFF);
lv_slider_set_left_value(slider, 20, LV_ANIM_OFF); lv_slider_set_left_value(slider, 20, LV_ANIM_OFF);

View File

@@ -10,30 +10,25 @@ static void event_handler(lv_obj_t * obj, lv_event_t event)
void lv_example_switch_1(void) void lv_example_switch_1(void)
{ {
lv_obj_set_layout(lv_scr_act(), &lv_flex_column_center); lv_obj_set_flex_flow(lv_scr_act(), LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_place(lv_scr_act(), LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_CENTER);
lv_obj_t * sw; lv_obj_t * sw;
sw = lv_switch_create(lv_scr_act(), NULL); sw = lv_switch_create(lv_scr_act(), NULL);
lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, -50);
lv_obj_add_event_cb(sw, event_handler, NULL); lv_obj_add_event_cb(sw, event_handler, NULL);
sw = lv_switch_create(lv_scr_act(), NULL); sw = lv_switch_create(lv_scr_act(), NULL);
lv_obj_add_state(sw, LV_STATE_CHECKED); lv_obj_add_state(sw, LV_STATE_CHECKED);
lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, 50);
lv_obj_add_event_cb(sw, event_handler, NULL); lv_obj_add_event_cb(sw, event_handler, NULL);
sw = lv_switch_create(lv_scr_act(), NULL); sw = lv_switch_create(lv_scr_act(), NULL);
lv_obj_add_state(sw, LV_STATE_DISABLED); lv_obj_add_state(sw, LV_STATE_DISABLED);
lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, 50);
lv_obj_add_event_cb(sw, event_handler, NULL); lv_obj_add_event_cb(sw, event_handler, NULL);
sw = lv_switch_create(lv_scr_act(), NULL); sw = lv_switch_create(lv_scr_act(), NULL);
lv_obj_add_state(sw, LV_STATE_CHECKED | LV_STATE_DISABLED); lv_obj_add_state(sw, LV_STATE_CHECKED | LV_STATE_DISABLED);
lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, 50);
lv_obj_add_event_cb(sw, event_handler, NULL); lv_obj_add_event_cb(sw, event_handler, NULL);
} }
#endif #endif

View File

@@ -36,7 +36,7 @@ void lv_example_tabview_1(void)
label = lv_label_create(tab3, NULL); label = lv_label_create(tab3, NULL);
lv_label_set_text(label, "Third tab"); lv_label_set_text(label, "Third tab");
lv_obj_scroll_to_view_recursive(label, 1); lv_obj_scroll_to_view_recursive(label, LV_ANIM_ON);
} }
#endif #endif

View File

@@ -821,7 +821,7 @@ static void indev_proc_press(lv_indev_proc_t * proc)
proc->types.pointer.vect.x = 0; proc->types.pointer.vect.x = 0;
proc->types.pointer.vect.y = 0; proc->types.pointer.vect.y = 0;
/*Send a Call the ancestor's event handler about the press*/ /*Call the ancestor's event handler about the press*/
lv_event_send(indev_obj_act, LV_EVENT_PRESSED, NULL); lv_event_send(indev_obj_act, LV_EVENT_PRESSED, NULL);
if(indev_reset_check(proc)) return; if(indev_reset_check(proc)) return;
@@ -859,7 +859,7 @@ static void indev_proc_press(lv_indev_proc_t * proc)
/*If there is no scrolling then check for long press time*/ /*If there is no scrolling then check for long press time*/
if(proc->types.pointer.scroll_obj == NULL && proc->long_pr_sent == 0) { if(proc->types.pointer.scroll_obj == NULL && proc->long_pr_sent == 0) {
/*Send a Call the ancestor's event handler about the long press if enough time elapsed*/ /*Call the ancestor's event handler about the long press if enough time elapsed*/
if(lv_tick_elaps(proc->pr_timestamp) > indev_act->driver->long_press_time) { if(lv_tick_elaps(proc->pr_timestamp) > indev_act->driver->long_press_time) {
lv_event_send(indev_obj_act, LV_EVENT_LONG_PRESSED, NULL); lv_event_send(indev_obj_act, LV_EVENT_LONG_PRESSED, NULL);
if(indev_reset_check(proc)) return; if(indev_reset_check(proc)) return;
@@ -874,7 +874,7 @@ static void indev_proc_press(lv_indev_proc_t * proc)
/*Send long press repeated Call the ancestor's event handler*/ /*Send long press repeated Call the ancestor's event handler*/
if(proc->types.pointer.scroll_obj == NULL && proc->long_pr_sent == 1) { if(proc->types.pointer.scroll_obj == NULL && proc->long_pr_sent == 1) {
/*Send a Call the ancestor's event handler about the long press repeat if enough time elapsed*/ /*Call the ancestor's event handler about the long press repeat if enough time elapsed*/
if(lv_tick_elaps(proc->longpr_rep_timestamp) > indev_act->driver->long_press_rep_time) { if(lv_tick_elaps(proc->longpr_rep_timestamp) > indev_act->driver->long_press_rep_time) {
lv_event_send(indev_obj_act, LV_EVENT_LONG_PRESSED_REPEAT, NULL); lv_event_send(indev_obj_act, LV_EVENT_LONG_PRESSED_REPEAT, NULL);
if(indev_reset_check(proc)) return; if(indev_reset_check(proc)) return;

View File

@@ -35,11 +35,7 @@ extern "C" {
*/ */
void lv_indev_read_timer_cb(lv_timer_t * timer); void lv_indev_read_timer_cb(lv_timer_t * timer);
/**
* Enable or disable an input devices
* @param indev pointer to an input device
* @param en true: enable; false: disable
*/
void lv_indev_enable(lv_indev_t * indev, bool en); void lv_indev_enable(lv_indev_t * indev, bool en);
/** /**

View File

@@ -298,7 +298,6 @@ lv_res_t lv_obj_event_base(const lv_obj_class_t * class_p, struct _lv_obj_t * ob
event_temp_data_head = event_temp_data_head->prev; event_temp_data_head = event_temp_data_head->prev;
return res; return res;
} }
@@ -612,64 +611,16 @@ static void lv_obj_constructor(lv_obj_t * obj, const lv_obj_t * copy)
LV_TRACE_OBJ_CREATE("begin"); LV_TRACE_OBJ_CREATE("begin");
lv_obj_t * parent = obj->parent; lv_obj_t * parent = obj->parent;
/*Create a screen*/ if(parent) {
if(parent == NULL) {
LV_TRACE_OBJ_CREATE("creating a screen");
lv_disp_t * disp = lv_disp_get_default();
if(!disp) {
LV_LOG_WARN("No display created to so far. No place to assign the new screen");
return;
}
if(disp->screens == NULL) {
disp->screens = lv_mem_alloc(sizeof(lv_obj_t *));
disp->screens[0] = obj;
disp->screen_cnt = 1;
} else {
disp->screen_cnt++;
disp->screens = lv_mem_realloc(disp->screens, sizeof(lv_obj_t *) * disp->screen_cnt);
disp->screens[disp->screen_cnt - 1] = obj;
}
/*Set coordinates to full screen size*/
obj->coords.x1 = 0;
obj->coords.y1 = 0;
obj->coords.x2 = lv_disp_get_hor_res(NULL) - 1;
obj->coords.y2 = lv_disp_get_ver_res(NULL) - 1;
}
/*Create a normal object*/
else {
LV_TRACE_OBJ_CREATE("creating normal object");
LV_ASSERT_OBJ(parent, MY_CLASS);
if(parent->spec_attr == NULL) {
lv_obj_allocate_spec_attr(parent);
}
if(parent->spec_attr->children == NULL) {
parent->spec_attr->children = lv_mem_alloc(sizeof(lv_obj_t *));
parent->spec_attr->children[0] = obj;
parent->spec_attr->child_cnt = 1;
} else {
parent->spec_attr->child_cnt++;
parent->spec_attr->children = lv_mem_realloc(parent->spec_attr->children, sizeof(lv_obj_t *) * parent->spec_attr->child_cnt);
parent->spec_attr->children[parent->spec_attr->child_cnt - 1] = obj;
}
lv_coord_t sl = lv_obj_get_scroll_left(parent); lv_coord_t sl = lv_obj_get_scroll_left(parent);
lv_coord_t st = lv_obj_get_scroll_top(parent); lv_coord_t st = lv_obj_get_scroll_top(parent);
obj->coords.y1 = parent->coords.y1 + lv_obj_get_style_pad_top(parent, LV_PART_MAIN) - st; obj->coords.y1 = parent->coords.y1 + lv_obj_get_style_pad_top(parent, LV_PART_MAIN) - st;
obj->coords.y2 = obj->coords.y1 + LV_OBJ_DEF_HEIGHT; obj->coords.y2 = obj->coords.y1 - 1;
if(lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL) { obj->coords.x1 = parent->coords.x1 + lv_obj_get_style_pad_left(parent, LV_PART_MAIN) - sl;
obj->coords.x2 = parent->coords.x2 - lv_obj_get_style_pad_right(parent, LV_PART_MAIN) - sl; obj->coords.x2 = obj->coords.x1 - 1;
obj->coords.x1 = obj->coords.x2 - LV_OBJ_DEF_WIDTH;
} lv_obj_set_size(obj, LV_OBJ_DEF_WIDTH, LV_OBJ_DEF_HEIGHT);
else {
obj->coords.x1 = parent->coords.x1 + lv_obj_get_style_pad_left(parent, LV_PART_MAIN) - sl;
obj->coords.x2 = obj->coords.x1 + LV_OBJ_DEF_WIDTH;
}
obj->w_set = lv_area_get_width(&obj->coords);
obj->h_set = lv_area_get_height(&obj->coords);
} }
/*Set attributes*/ /*Set attributes*/
@@ -683,30 +634,6 @@ static void lv_obj_constructor(lv_obj_t * obj, const lv_obj_t * copy)
obj->flags |= LV_OBJ_FLAG_SCROLL_MOMENTUM; obj->flags |= LV_OBJ_FLAG_SCROLL_MOMENTUM;
if(parent) obj->flags |= LV_OBJ_FLAG_GESTURE_BUBBLE; if(parent) obj->flags |= LV_OBJ_FLAG_GESTURE_BUBBLE;
/*Copy the attributes if required*/
if(copy != NULL) {
lv_area_copy(&obj->coords, &copy->coords);
obj->flags = copy->flags;
if(copy->spec_attr) {
lv_obj_allocate_spec_attr(obj);
lv_memcpy_small(obj->spec_attr, copy->spec_attr, sizeof(lv_obj_spec_attr_t));
obj->spec_attr->children = NULL; /*Make the child list empty*/
}
/*Add to the same group*/
if(copy->spec_attr && copy->spec_attr->group_p) {
obj->spec_attr->group_p = NULL; /*It was simply copied*/
lv_group_add_obj(copy->spec_attr->group_p, obj);
}
/*Set the same coordinates for non screen objects*/
if(lv_obj_get_parent(copy) != NULL && parent != NULL) {
lv_obj_set_pos(obj, lv_obj_get_x(copy), lv_obj_get_y(copy));
lv_obj_set_size(obj, lv_obj_get_width(copy), lv_obj_get_height(copy));
}
}
LV_TRACE_OBJ_CREATE("finished"); LV_TRACE_OBJ_CREATE("finished");
} }
@@ -900,6 +827,7 @@ static lv_res_t scrollbar_init_draw_dsc(lv_obj_t * obj, lv_draw_rect_dsc_t * dsc
#endif #endif
} }
#include "lvgl/lvgl.h"
static void lv_obj_event_cb(lv_obj_t * obj, lv_event_t e) static void lv_obj_event_cb(lv_obj_t * obj, lv_event_t e)
{ {
@@ -972,62 +900,22 @@ static void lv_obj_event_cb(lv_obj_t * obj, lv_event_t e)
lv_obj_clear_state(obj, LV_STATE_FOCUSED | LV_STATE_EDITED | LV_STATE_FOCUS_KEY); lv_obj_clear_state(obj, LV_STATE_FOCUSED | LV_STATE_EDITED | LV_STATE_FOCUS_KEY);
} }
else if(e == LV_EVENT_COORD_CHANGED) { else if(e == LV_EVENT_SIZE_CHANGED) {
bool w_new = true; uint32_t i;
bool h_new = true; for(i = 0; i < lv_obj_get_child_cnt(obj); i++) {
void * param = lv_event_get_param(); lv_obj_t * child = lv_obj_get_child(obj, i);
if(param) {
if(lv_area_get_width(param) == lv_obj_get_width(obj)) w_new = false; lv_obj_refr_size(child);
if(lv_area_get_height(param) == lv_obj_get_height(obj)) h_new = false;
} }
if(w_new || h_new) { if(lv_obj_get_style_layout(obj, LV_PART_MAIN)) {
uint32_t i = 0;
for(i = 0; i < lv_obj_get_child_cnt(obj); i++) {
lv_obj_t * child = lv_obj_get_child(obj, i);
if((LV_COORD_IS_PCT(child->w_set) && w_new) ||
(LV_COORD_IS_PCT(child->h_set) && h_new))
{
lv_obj_set_size(child, child->w_set, child->h_set);
}
}
lv_obj_mark_layout_as_dirty(obj); lv_obj_mark_layout_as_dirty(obj);
} }
if(h_new) {
/*Be sure the bottom side is not remains scrolled in*/
lv_coord_t st = lv_obj_get_scroll_top(obj);
lv_coord_t sb = lv_obj_get_scroll_bottom(obj);
if(sb < 0 && st > 0) {
sb = LV_MIN(st, -sb);
lv_obj_scroll_by(obj, 0, sb, LV_ANIM_OFF);
}
}
if(w_new) {
lv_coord_t sl = lv_obj_get_scroll_left(obj);
lv_coord_t sr = lv_obj_get_scroll_right(obj);
if(lv_obj_get_base_dir(obj) != LV_BIDI_DIR_RTL) {
/*Be sure the left side is not remains scrolled in*/
if(sr < 0 && sl > 0) {
sr = LV_MIN(sl, -sr);
lv_obj_scroll_by(obj, 0, sr, LV_ANIM_OFF);
}
} else {
/*Be sure the right side is not remains scrolled in*/
if(sl < 0 && sr > 0) {
sr = LV_MIN(sr, -sl);
lv_obj_scroll_by(obj, 0, sl, LV_ANIM_OFF);
}
}
}
} }
else if(e == LV_EVENT_CHILD_CHANGED) { else if(e == LV_EVENT_CHILD_CHANGED) {
lv_obj_mark_layout_as_dirty(obj); // lv_obj_mark_layout_as_dirty(obj);
if(lv_obj_get_style_layout(obj, LV_PART_MAIN)) {
if(obj->w_set == LV_SIZE_CONTENT || obj->h_set == LV_SIZE_CONTENT) { lv_obj_mark_layout_as_dirty(obj);
lv_obj_set_size(obj, obj->w_set, obj->h_set);
} }
} }
else if(e == LV_EVENT_BASE_DIR_CHANGED) { else if(e == LV_EVENT_BASE_DIR_CHANGED) {
@@ -1047,20 +935,18 @@ static void lv_obj_event_cb(lv_obj_t * obj, lv_event_t e)
} }
else if(e == LV_EVENT_STYLE_CHANGED) { else if(e == LV_EVENT_STYLE_CHANGED) {
/*Padding might have changed so the layout should be recalculated*/ /*Padding might have changed so the layout should be recalculated*/
lv_obj_mark_layout_as_dirty(obj);
/*Reposition non grid objects on by one*/
uint32_t i; uint32_t i;
for(i = 0; i < lv_obj_get_child_cnt(obj); i++) { for(i = 0; i < lv_obj_get_child_cnt(obj); i++) {
lv_obj_t * child = lv_obj_get_child(obj, i); lv_obj_t * child = lv_obj_get_child(obj, i);
if(LV_COORD_IS_PX(child->x_set) || LV_COORD_IS_PX(child->y_set)) {
lv_obj_set_pos(child, child->x_set, child->y_set); lv_obj_refr_size(child);
} lv_obj_refr_pos(child);
} }
if(obj->w_set == LV_SIZE_CONTENT || obj->h_set == LV_SIZE_CONTENT) { if(lv_obj_get_style_layout(obj, LV_PART_MAIN)) {
lv_obj_set_size(obj, obj->w_set, obj->h_set); lv_obj_mark_layout_as_dirty(obj);
} }
lv_obj_refresh_ext_draw_size(obj); lv_obj_refresh_ext_draw_size(obj);
} }
else if(e == LV_EVENT_DRAW_MAIN || e == LV_EVENT_DRAW_POST || e == LV_EVENT_COVER_CHECK) { else if(e == LV_EVENT_DRAW_MAIN || e == LV_EVENT_DRAW_POST || e == LV_EVENT_COVER_CHECK) {
@@ -1190,7 +1076,7 @@ static bool event_is_bubbled(lv_event_t e)
case LV_EVENT_REFRESH: case LV_EVENT_REFRESH:
case LV_EVENT_DELETE: case LV_EVENT_DELETE:
case LV_EVENT_CHILD_CHANGED: case LV_EVENT_CHILD_CHANGED:
case LV_EVENT_COORD_CHANGED: case LV_EVENT_SIZE_CHANGED:
case LV_EVENT_STYLE_CHANGED: case LV_EVENT_STYLE_CHANGED:
case LV_EVENT_GET_SELF_SIZE: case LV_EVENT_GET_SELF_SIZE:
return false; return false;

View File

@@ -82,7 +82,7 @@ typedef enum {
LV_EVENT_READY, /**< A process has finished*/ LV_EVENT_READY, /**< A process has finished*/
LV_EVENT_CANCEL, /**< A process has been cancelled */ LV_EVENT_CANCEL, /**< A process has been cancelled */
LV_EVENT_CHILD_CHANGED, /**< Child was removed/added*/ LV_EVENT_CHILD_CHANGED, /**< Child was removed/added*/
LV_EVENT_COORD_CHANGED, /**< Object coordinates/size have changed*/ LV_EVENT_SIZE_CHANGED, /**< Object coordinates/size have changed*/
LV_EVENT_STYLE_CHANGED, /**< Object's style has changed*/ LV_EVENT_STYLE_CHANGED, /**< Object's style has changed*/
LV_EVENT_BASE_DIR_CHANGED, /**< The base dir has changed*/ LV_EVENT_BASE_DIR_CHANGED, /**< The base dir has changed*/
LV_EVENT_GET_SELF_SIZE, /**< Get the internal size of a widget*/ LV_EVENT_GET_SELF_SIZE, /**< Get the internal size of a widget*/
@@ -220,8 +220,6 @@ typedef struct {
uint32_t child_cnt; /**< Number of children*/ uint32_t child_cnt; /**< Number of children*/
lv_group_t * group_p; lv_group_t * group_p;
const lv_layout_dsc_t * layout_dsc; /**< Pointer to the layout descriptor*/
lv_event_dsc_t * event_dsc; /**< Dynamically allocated event callback and user data array*/ lv_event_dsc_t * event_dsc; /**< Dynamically allocated event callback and user data array*/
lv_point_t scroll; /**< The current X/Y scroll offset*/ lv_point_t scroll; /**< The current X/Y scroll offset*/
@@ -242,15 +240,13 @@ typedef struct _lv_obj_t {
lv_obj_spec_attr_t * spec_attr; lv_obj_spec_attr_t * spec_attr;
lv_obj_style_t * styles; lv_obj_style_t * styles;
lv_area_t coords; lv_area_t coords;
lv_coord_t x_set;
lv_coord_t y_set;
lv_coord_t w_set;
lv_coord_t h_set;
lv_obj_flag_t flags; lv_obj_flag_t flags;
lv_state_t state; lv_state_t state;
uint8_t layout_inv :1; uint16_t layout_inv :1;
uint8_t skip_trans :1; uint16_t skip_trans :1;
uint8_t style_cnt :6; uint16_t style_cnt :6;
uint16_t h_layout :1;
uint16_t w_layout :1;
}lv_obj_t; }lv_obj_t;

View File

@@ -49,20 +49,18 @@ lv_obj_t * lv_obj_create_from_class(const lv_obj_class_t * class_p, lv_obj_t * p
obj->class_p = class_p; obj->class_p = class_p;
obj->parent = parent; obj->parent = parent;
lv_theme_apply(obj);
lv_obj_construct(obj, copy); lv_obj_construct(obj, copy);
if(parent) { if(parent) {
/*Send a Call the ancestor's event handler to the parent to notify it about the new child. /*Call the ancestor's event handler to the parent to notify it about the new child.
*Also triggers layout update*/ *Also triggers layout update*/
lv_event_send(parent, LV_EVENT_CHILD_CHANGED, obj); lv_event_send(parent, LV_EVENT_CHILD_CHANGED, obj);
/*Invalidate the area if not screen created*/ /*Invalidate the area if not screen created*/
lv_obj_invalidate(obj); lv_obj_invalidate(obj);
} }
if(!copy) lv_theme_apply(obj);
LV_TRACE_OBJ_CREATE("Object created at %p address with %p class on %p parent", obj, class_p, parent);
return obj; return obj;
} }

View File

@@ -22,15 +22,14 @@
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static bool refr_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h);
static void calc_auto_size(lv_obj_t * obj, lv_coord_t * w_out, lv_coord_t * h_out); static void calc_auto_size(lv_obj_t * obj, lv_coord_t * w_out, lv_coord_t * h_out);
static void layout_update_core(lv_obj_t * obj); static void layout_update_core(lv_obj_t * obj);
void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, bool notify);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
**********************/ **********************/
static lv_layout_update_cb_t * layouts;
static uint32_t layout_cnt;
/********************** /**********************
* MACROS * MACROS
@@ -44,50 +43,69 @@ void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
if(lv_obj_is_layout_positioned(obj)) { lv_obj_set_x(obj, x);
return; lv_obj_set_y(obj, y);
}
obj->x_set = x;
obj->y_set = y;
lv_obj_move_to(obj, x, y, true);
} }
void lv_obj_set_x(lv_obj_t * obj, lv_coord_t x) void lv_obj_set_x(lv_obj_t * obj, lv_coord_t x)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
if(lv_obj_is_layout_positioned(obj)) {
return;
}
lv_obj_set_pos(obj, x, obj->y_set); lv_res_t res_x;
lv_style_value_t v_x;
res_x = lv_obj_get_local_style_prop(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_STYLE_X, &v_x);
if((res_x == LV_RES_OK && v_x.num != x) || res_x == LV_RES_INV) {
lv_obj_set_style_x(obj, LV_PART_MAIN, LV_STATE_DEFAULT, x);
}
lv_obj_refr_pos(obj);
} }
void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y) void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y)
{ {
if(lv_obj_is_layout_positioned(obj)) {
return;
}
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
lv_obj_set_pos(obj, obj->x_set, y); lv_res_t res_y;
lv_style_value_t v_y;
res_y = lv_obj_get_local_style_prop(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_STYLE_Y, &v_y);
if((res_y == LV_RES_OK && v_y.num != y) || res_y == LV_RES_INV) {
lv_obj_set_style_y(obj, LV_PART_MAIN, LV_STATE_DEFAULT, y);
}
lv_obj_refr_pos(obj);
} }
void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) void lv_obj_refr_size(lv_obj_t * obj)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
/*If the width or height is set by a layout do not modify them*/ /*If the width or height is set by a layout do not modify them*/
if(obj->w_set == LV_SIZE_LAYOUT && obj->h_set == LV_SIZE_LAYOUT) return; if(obj->w_layout && obj->h_layout) return;
if(obj->w_set == LV_SIZE_LAYOUT) w = lv_obj_get_width(obj);
if(obj->h_set == LV_SIZE_LAYOUT) h = lv_obj_get_height(obj);
obj->w_set = w; lv_obj_t * parent = lv_obj_get_parent(obj);
obj->h_set = h; if(parent == NULL) return;
/*If the width or height is set to special layout related value save them in w_set and h_set lv_coord_t w;
*but use the current size on the object width*/ lv_coord_t h;
if(LV_COORD_IS_LAYOUT(w)) w = lv_obj_get_width(obj); if(obj->w_layout) w = lv_obj_get_width(obj);
if(LV_COORD_IS_LAYOUT(h)) h = lv_obj_get_height(obj); else w = lv_obj_get_style_width(obj, LV_PART_MAIN);
if(obj->h_layout) h = lv_obj_get_height(obj);
else h = lv_obj_get_style_height(obj, LV_PART_MAIN);
/*Calculate the required auto sizes*/ /*Calculate the required auto sizes*/
bool w_content = obj->w_set == LV_SIZE_CONTENT ? true : false; bool w_content = w == LV_SIZE_CONTENT ? true : false;
bool h_content = obj->h_set == LV_SIZE_CONTENT ? true : false; bool h_content = h == LV_SIZE_CONTENT ? true : false;
/*Be sure the object is not scrolled when it has auto size*/ /*Be sure the object is not scrolled when it has auto size*/
if(w_content) lv_obj_scroll_to_x(obj, 0, LV_ANIM_OFF); if(w_content) lv_obj_scroll_to_x(obj, 0, LV_ANIM_OFF);
@@ -98,32 +116,97 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h)
else if(h_content) calc_auto_size(obj, NULL, &h); else if(h_content) calc_auto_size(obj, NULL, &h);
/*Calculate the required auto sizes*/ /*Calculate the required auto sizes*/
bool pct_w = LV_COORD_IS_PCT(obj->w_set) ? true : false; bool pct_w = LV_COORD_IS_PCT(w) ? true : false;
bool pct_h = LV_COORD_IS_PCT(obj->h_set) ? true : false; bool pct_h = LV_COORD_IS_PCT(h) ? true : false;
lv_obj_t * parent = lv_obj_get_parent(obj); lv_coord_t parent_w = lv_obj_get_width_fit(parent);
if(parent) { lv_coord_t parent_h = lv_obj_get_height_fit(parent);
lv_coord_t parent_w = lv_obj_get_width_fit(parent); if(pct_w) w = (LV_COORD_GET_PCT(w) * parent_w) / 100;
lv_coord_t parent_h = lv_obj_get_height_fit(parent); if(pct_h) h = (LV_COORD_GET_PCT(h) * parent_h) / 100;
if(pct_w) w = (LV_COORD_GET_PCT(obj->w_set) * parent_w) / 100;
if(pct_h) h = (LV_COORD_GET_PCT(obj->h_set) * parent_h) / 100; /*Do nothing if the size is not changed*/
/*It is very important else recursive resizing can occur without size change*/
if(lv_obj_get_width(obj) == w && lv_obj_get_height(obj) == h) return;
/*Invalidate the original area*/
lv_obj_invalidate(obj);
/*Save the original coordinates*/
lv_area_t ori;
lv_obj_get_coords(obj, &ori);
/*Check if the object inside the parent or not*/
lv_area_t parent_fit_area;
lv_obj_get_coords_fit(parent, &parent_fit_area);
/*If the object is already out of the parent and its position is changes
*surely the scrollbars also changes so invalidate them*/
bool on1 = _lv_area_is_in(&ori, &parent_fit_area, 0);
if(!on1) lv_obj_scrollbar_invalidate(parent);
/*Set the length and height
*Be sure the content is not scrolled in an invalid position on the new size*/
obj->coords.y2 = obj->coords.y1 + h - 1;
if(lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL) {
obj->coords.x1 = obj->coords.x2 - w + 1;
}
else {
obj->coords.x2 = obj->coords.x1 + w - 1;
} }
refr_size(obj, w, h); /*Call the ancestor's event handler to the object with its new coordinates*/
lv_event_send(obj, LV_EVENT_SIZE_CHANGED, &ori);
/*Call the ancestor's event handler to the parent too*/
lv_event_send(parent, LV_EVENT_CHILD_CHANGED, obj);
/*Invalidate the new area*/
lv_obj_invalidate(obj);
/*Calculate the required auto sizes*/
/*If the object was out of the parent invalidate the new scrollbar area too.
*If it wasn't out of the parent but out now, also invalidate the srollbars*/
bool on2 = _lv_area_is_in(&obj->coords, &parent_fit_area, 0);
if(on1 || (!on1 && on2)) lv_obj_scrollbar_invalidate(parent);
}
void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_obj_set_width(obj, w);
lv_obj_set_height(obj, h);
} }
void lv_obj_set_width(lv_obj_t * obj, lv_coord_t w) void lv_obj_set_width(lv_obj_t * obj, lv_coord_t w)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
lv_res_t res_w;
lv_style_value_t v_w;
lv_obj_set_size(obj, w, obj->h_set); res_w = lv_obj_get_local_style_prop(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_STYLE_WIDTH, &v_w);
if((res_w == LV_RES_OK && v_w.num != w) || res_w == LV_RES_INV) {
lv_obj_set_style_width(obj, LV_PART_MAIN, LV_STATE_DEFAULT, w);
}
lv_obj_refr_size(obj);
} }
void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h) void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
lv_res_t res_h;
lv_style_value_t v_h;
lv_obj_set_size(obj, obj->w_set, h); res_h = lv_obj_get_local_style_prop(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_STYLE_HEIGHT, &v_h);
if((res_h == LV_RES_OK && v_h.num != h) || res_h == LV_RES_INV) {
lv_obj_set_style_height(obj, LV_PART_MAIN, LV_STATE_DEFAULT, h);
}
lv_obj_refr_size(obj);
} }
void lv_obj_set_content_width(lv_obj_t * obj, lv_coord_t w) void lv_obj_set_content_width(lv_obj_t * obj, lv_coord_t w)
@@ -142,12 +225,11 @@ void lv_obj_set_content_height(lv_obj_t * obj, lv_coord_t h)
lv_obj_set_height(obj, h + ptop + pbottom); lv_obj_set_height(obj, h + ptop + pbottom);
} }
void lv_obj_set_layout(lv_obj_t * obj, const void * layout) void lv_obj_set_layout(lv_obj_t * obj, uint32_t layout)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
lv_obj_allocate_spec_attr(obj); lv_obj_set_style_layout(obj, LV_PART_MAIN, LV_STATE_DEFAULT, layout);
obj->spec_attr->layout_dsc = layout;
lv_obj_mark_layout_as_dirty(obj); lv_obj_mark_layout_as_dirty(obj);
} }
@@ -158,7 +240,9 @@ bool lv_obj_is_layout_positioned(const lv_obj_t * obj)
lv_obj_t * parent = lv_obj_get_parent(obj); lv_obj_t * parent = lv_obj_get_parent(obj);
if(parent == NULL) return false; if(parent == NULL) return false;
if(parent->spec_attr && parent->spec_attr->layout_dsc) return true;
uint32_t layout = lv_obj_get_style_layout(parent, LV_PART_MAIN);
if(layout) return true;
else return false; else return false;
} }
@@ -177,27 +261,41 @@ void lv_obj_mark_layout_as_dirty(lv_obj_t * obj)
void lv_obj_update_layout(lv_obj_t * obj) void lv_obj_update_layout(lv_obj_t * obj)
{ {
static bool mutex = false;
if(mutex) {
LV_LOG_TRACE("Already running, returning")
return;
}
mutex = true;
lv_obj_t * scr = lv_obj_get_screen(obj); lv_obj_t * scr = lv_obj_get_screen(obj);
/*There are no dirty layouts on this screen*/ /*Repeat until there where layout invalidations*/
if(scr->layout_inv == 0) return; while(scr->layout_inv) {
LV_LOG_INFO("Start layout update")
do {
scr->layout_inv = 0; scr->layout_inv = 0;
layout_update_core(obj); layout_update_core(scr);
}while(scr->layout_inv); /*Repeat until there where layout invalidations*/ LV_LOG_TRACE("Layout update finished")
}
/*Restore the global state because other calls of this function needs this info too. mutex = false;
*Other calls might use different start object, but they need to know if there is dirty layout somewhere. }
*However if the screen was updated it's sure that all layouts are ready.*/
if(obj != scr) scr->layout_inv = 1;
uint32_t lv_layout_register(lv_layout_update_cb_t cb)
{
layout_cnt++;
layouts = lv_mem_realloc(layouts, layout_cnt * sizeof(lv_layout_update_cb_t));
LV_ASSERT_MALLOC(layouts);
layouts[layout_cnt - 1] = cb;
return layout_cnt; /*No -1 to skip 0th index*/
} }
void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs) void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
lv_obj_update_layout(obj);
if(base == NULL) base = lv_obj_get_parent(obj); if(base == NULL) base = lv_obj_get_parent(obj);
LV_ASSERT_OBJ(base, MY_CLASS); LV_ASSERT_OBJ(base, MY_CLASS);
@@ -311,8 +409,8 @@ void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_co
break; break;
} }
x += x_ofs + base->coords.x1 - parent->coords.x1; x += x_ofs + base->coords.x1 - parent->coords.x1 + lv_obj_get_scroll_left(parent);
y += y_ofs + base->coords.y1 - parent->coords.y1; y += y_ofs + base->coords.y1 - parent->coords.y1 + lv_obj_get_scroll_top(parent);
lv_obj_set_pos(obj, x, y); lv_obj_set_pos(obj, x, y);
} }
@@ -341,6 +439,13 @@ lv_coord_t lv_obj_get_x(const lv_obj_t * obj)
return rel_x; return rel_x;
} }
lv_coord_t lv_obj_get_x2(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
return lv_obj_get_x(obj) + lv_obj_get_width(obj);
}
lv_coord_t lv_obj_get_y(const lv_obj_t * obj) lv_coord_t lv_obj_get_y(const lv_obj_t * obj)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
@@ -358,6 +463,13 @@ lv_coord_t lv_obj_get_y(const lv_obj_t * obj)
return rel_y; return rel_y;
} }
lv_coord_t lv_obj_get_y2(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
return lv_obj_get_y(obj) + lv_obj_get_height(obj);
}
lv_coord_t lv_obj_get_width(const lv_obj_t * obj) lv_coord_t lv_obj_get_width(const lv_obj_t * obj)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
@@ -406,7 +518,7 @@ void lv_obj_get_coords_fit(const lv_obj_t * obj, lv_area_t * area)
lv_coord_t lv_obj_get_height_visible(const lv_obj_t * obj) lv_coord_t lv_obj_get_height_visible(const lv_obj_t * obj)
{ {
lv_obj_update_layout(lv_obj_get_screen(obj)); lv_obj_update_layout(obj);
lv_coord_t h = LV_COORD_MAX; lv_coord_t h = LV_COORD_MAX;
lv_obj_t * parent = lv_obj_get_parent(obj); lv_obj_t * parent = lv_obj_get_parent(obj);
@@ -420,7 +532,7 @@ lv_coord_t lv_obj_get_height_visible(const lv_obj_t * obj)
lv_coord_t lv_obj_get_width_visible(const lv_obj_t * obj) lv_coord_t lv_obj_get_width_visible(const lv_obj_t * obj)
{ {
lv_obj_update_layout(lv_obj_get_screen(obj)); lv_obj_update_layout(obj);
lv_coord_t w = LV_COORD_MAX; lv_coord_t w = LV_COORD_MAX;
lv_obj_t * parent = lv_obj_get_parent(obj); lv_obj_t * parent = lv_obj_get_parent(obj);
@@ -448,14 +560,25 @@ lv_coord_t lv_obj_get_self_height(struct _lv_obj_t * obj)
bool lv_obj_handle_self_size_chg(struct _lv_obj_t * obj) bool lv_obj_handle_self_size_chg(struct _lv_obj_t * obj)
{ {
if(obj->w_set != LV_SIZE_CONTENT && obj->h_set == LV_SIZE_CONTENT) return false; lv_coord_t w_set = lv_obj_get_style_width(obj, LV_PART_MAIN);
lv_coord_t h_set = lv_obj_get_style_height(obj, LV_PART_MAIN);
if(w_set != LV_SIZE_CONTENT && h_set == LV_SIZE_CONTENT) return false;
lv_obj_set_size(obj, obj->w_set, obj->h_set); lv_obj_refr_size(obj);
return true; return true;
} }
void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, bool notify) void lv_obj_refr_pos(lv_obj_t * obj)
{ {
lv_coord_t x = lv_obj_get_style_x(obj, LV_PART_MAIN);
lv_coord_t y = lv_obj_get_style_y(obj, LV_PART_MAIN);
lv_obj_move_to(obj, x, y);
}
void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y)
{
if(lv_obj_is_layout_positioned(obj)) return;
/*Convert x and y to absolute coordinates*/ /*Convert x and y to absolute coordinates*/
lv_obj_t * parent = obj->parent; lv_obj_t * parent = obj->parent;
@@ -503,11 +626,8 @@ void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, bool notify)
lv_obj_move_children_by(obj, diff.x, diff.y, false); lv_obj_move_children_by(obj, diff.x, diff.y, false);
/*Inform the object about its new coordinates*/ /*Call the ancestor's event handler to the parent too*/
lv_event_send(obj, LV_EVENT_COORD_CHANGED, &ori); if(parent) lv_event_send(parent, LV_EVENT_CHILD_CHANGED, obj);
/*Send a Call the ancestor's event handler to the parent too*/
if(parent && notify) lv_event_send(parent, LV_EVENT_CHILD_CHANGED, obj);
/*Invalidate the new area*/ /*Invalidate the new area*/
lv_obj_invalidate(obj); lv_obj_invalidate(obj);
@@ -664,71 +784,6 @@ bool lv_obj_hit_test(lv_obj_t * obj, const lv_point_t * point)
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
/**
* Set the size of an object.
* It's the core function to set the size of objects but user should use `lv_obj_set_size/width/height/..` etc.
* @param obj pointer to an object
* @param w the new width in pixels
* @param h the new height in pixels
* @return true: the size was changed; false: `w` and `h` was equal to the current width and height so nothing happened.
*/
static bool refr_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h)
{
lv_obj_t * parent = lv_obj_get_parent(obj);
if(parent == NULL) return false;
/*If the size is managed by the layout don't let to overwrite it.*/
if(obj->w_set == LV_SIZE_LAYOUT) w = lv_obj_get_width(obj);
if(obj->h_set == LV_SIZE_LAYOUT) h = lv_obj_get_height(obj);
/*Do nothing if the size is not changed*/
/*It is very important else recursive resizing can
*occur without size change*/
if(lv_obj_get_width(obj) == w && lv_obj_get_height(obj) == h) {
return false;
}
/*Invalidate the original area*/
lv_obj_invalidate(obj);
/*Save the original coordinates*/
lv_area_t ori;
lv_obj_get_coords(obj, &ori);
/*Check if the object inside the parent or not*/
lv_area_t parent_fit_area;
lv_obj_get_coords_fit(parent, &parent_fit_area);
/*If the object is already out of the parent and its position is changes
*surely the scrollbars also changes so invalidate them*/
bool on1 = _lv_area_is_in(&ori, &parent_fit_area, 0);
if(!on1) lv_obj_scrollbar_invalidate(parent);
/*Set the length and height
*Be sure the content is not scrolled in an invalid position on the new size*/
obj->coords.y2 = obj->coords.y1 + h - 1;
if(lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL) {
obj->coords.x1 = obj->coords.x2 - w + 1;
}
else {
obj->coords.x2 = obj->coords.x1 + w - 1;
}
/*Send a Call the ancestor's event handler to the object with its new coordinates*/
lv_event_send(obj, LV_EVENT_COORD_CHANGED, &ori);
/*Send a Call the ancestor's event handler to the parent too*/
if(parent != NULL) lv_event_send(parent, LV_EVENT_CHILD_CHANGED, obj);
/*Invalidate the new area*/
lv_obj_invalidate(obj);
/*If the object was out of the parent invalidate the new scrollbar area too.
*If it wasn't out of the parent but out now, also invalidate the srollbars*/
bool on2 = _lv_area_is_in(&obj->coords, &parent_fit_area, 0);
if(on1 || (!on1 && on2)) lv_obj_scrollbar_invalidate(parent);
return true;
}
/** /**
* Calculate the "auto size". It's `auto_size = max(children_size, self_size)` * Calculate the "auto size". It's `auto_size = max(children_size, self_size)`
@@ -761,12 +816,41 @@ static void layout_update_core(lv_obj_t * obj)
layout_update_core(child); layout_update_core(child);
} }
if(!obj->layout_inv) return; if(obj->layout_inv == 0) return;
const lv_layout_dsc_t * layout = obj->spec_attr ? obj->spec_attr->layout_dsc : NULL; if(lv_obj_get_screen(obj) != obj) obj->layout_inv = 0;
const lv_layout_update_cb_t update_cp = layout ? layout->update_cb : NULL;
if(update_cp != NULL && lv_obj_get_child_cnt(obj) > 0) { lv_obj_refr_size(obj);
obj->layout_inv = 0; lv_obj_refr_pos(obj);
update_cp(obj);
/*Be sure the bottom side is not remains scrolled in*/
lv_coord_t st = lv_obj_get_scroll_top(obj);
lv_coord_t sb = lv_obj_get_scroll_bottom(obj);
if(sb < 0 && st > 0) {
sb = LV_MIN(st, -sb);
lv_obj_scroll_by(obj, 0, sb, LV_ANIM_OFF);
}
lv_coord_t sl = lv_obj_get_scroll_left(obj);
lv_coord_t sr = lv_obj_get_scroll_right(obj);
if(lv_obj_get_base_dir(obj) != LV_BIDI_DIR_RTL) {
/*Be sure the left side is not remains scrolled in*/
if(sr < 0 && sl > 0) {
sr = LV_MIN(sl, -sr);
lv_obj_scroll_by(obj, 0, sr, LV_ANIM_OFF);
}
} else {
/*Be sure the right side is not remains scrolled in*/
if(sl < 0 && sr > 0) {
sr = LV_MIN(sr, -sl);
lv_obj_scroll_by(obj, 0, sl, LV_ANIM_OFF);
}
}
if(lv_obj_get_child_cnt(obj) > 0) {
uint32_t layout_id = lv_obj_get_style_layout(obj, LV_PART_MAIN);
if(layout_id > 0 && layout_id <= layout_cnt) {
layouts[layout_id -1](obj);
}
} }
} }

View File

@@ -23,17 +23,7 @@ extern "C" {
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
struct _lv_obj_t; struct _lv_obj_t;
typedef void (*lv_layout_update_cb_t)(struct _lv_obj_t *);
typedef void (*lv_layout_update_cb_t)(struct _lv_obj_t * cont);
/**
* The base of all layouts descriptor.
* Every custom layout descriptor needs to extend this struct
* by adding `lv_layout_dsc_t` as the first element.
*/
typedef struct {
lv_layout_update_cb_t update_cb;
}lv_layout_dsc_t;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
@@ -74,6 +64,8 @@ void lv_obj_set_y(struct _lv_obj_t * obj, lv_coord_t y);
*/ */
void lv_obj_set_size(struct _lv_obj_t * obj, lv_coord_t w, lv_coord_t h); void lv_obj_set_size(struct _lv_obj_t * obj, lv_coord_t w, lv_coord_t h);
void lv_obj_refr_size(struct _lv_obj_t * obj);
/** /**
* Set the width of an object * Set the width of an object
* @param obj pointer to an object * @param obj pointer to an object
@@ -117,7 +109,7 @@ void lv_obj_set_content_height(struct _lv_obj_t * obj, lv_coord_t h);
* @param obj pointer to an object * @param obj pointer to an object
* @param layout pointer to a layout descriptor to set * @param layout pointer to a layout descriptor to set
*/ */
void lv_obj_set_layout(struct _lv_obj_t * obj, const void * layout); void lv_obj_set_layout(struct _lv_obj_t * obj, uint32_t layout);
/** /**
* Test whether the and object is positioned by a layout or not * Test whether the and object is positioned by a layout or not
@@ -138,6 +130,12 @@ void lv_obj_mark_layout_as_dirty(struct _lv_obj_t * obj);
*/ */
void lv_obj_update_layout(struct _lv_obj_t * obj); void lv_obj_update_layout(struct _lv_obj_t * obj);
/**
* Regsiter a new layout
* @param cb the layout update callback
* @return the ID of the new layout
*/
uint32_t lv_layout_register(lv_layout_update_cb_t cb);
/** /**
* Align an object to an other object. * Align an object to an other object.
@@ -178,6 +176,16 @@ void lv_obj_get_coords(const struct _lv_obj_t * obj, lv_area_t * coords);
*/ */
lv_coord_t lv_obj_get_x(const struct _lv_obj_t * obj); lv_coord_t lv_obj_get_x(const struct _lv_obj_t * obj);
/**
* Get the x2 coordinate of object.
* @param obj pointer to an object
* @return distance of `obj` from the right side of its parent plus the parent's right padding
* @note Zero return value means the object is on the right padding of the parent, and not on the right edge.
* @note Scrolling of the parent doesn't change the returned value.
* @note The returned value is always the distance from the parent even if `obj` is positioned by a layout.
*/
lv_coord_t lv_obj_get_x2(const struct _lv_obj_t * obj);
/** /**
* Get the y coordinate of object. * Get the y coordinate of object.
* @param obj pointer to an object * @param obj pointer to an object
@@ -188,6 +196,16 @@ lv_coord_t lv_obj_get_x(const struct _lv_obj_t * obj);
*/ */
lv_coord_t lv_obj_get_y(const struct _lv_obj_t * obj); lv_coord_t lv_obj_get_y(const struct _lv_obj_t * obj);
/**
* Get the y2 coordinate of object.
* @param obj pointer to an object
* @return distance of `obj` from the bottom side of its parent plus the parent's bottom padding
* @note Zero return value means the object is on the bottom padding of the parent, and not on the bottom edge.
* @note Scrolling of the parent doesn't change the returned value.
* @note The returned value is always the distance from the parent even if `obj` is positioned by a layout.
*/
lv_coord_t lv_obj_get_y2(const struct _lv_obj_t * obj);
/** /**
* Get the width of an object * Get the width of an object
* @param obj pointer to an object * @param obj pointer to an object
@@ -266,6 +284,9 @@ lv_coord_t lv_obj_get_self_height(struct _lv_obj_t * obj);
*/ */
bool lv_obj_handle_self_size_chg(struct _lv_obj_t * obj); bool lv_obj_handle_self_size_chg(struct _lv_obj_t * obj);
void lv_obj_refr_pos(struct _lv_obj_t * obj);
void lv_obj_move_to(struct _lv_obj_t * obj, lv_coord_t x, lv_coord_t y);
void lv_obj_move_children_by(struct _lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff, bool ignore_floating); void lv_obj_move_children_by(struct _lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff, bool ignore_floating);

View File

@@ -333,7 +333,7 @@ void lv_obj_scroll_to_y(lv_obj_t * obj, lv_coord_t y, lv_anim_enable_t anim_en)
void lv_obj_scroll_to_view(lv_obj_t * obj, lv_anim_enable_t anim_en) void lv_obj_scroll_to_view(lv_obj_t * obj, lv_anim_enable_t anim_en)
{ {
/*Be sure the screens layout is correct*/ /*Be sure the screens layout is correct*/
lv_obj_update_layout(lv_obj_get_screen(obj)); lv_obj_update_layout(obj);
lv_point_t p = {0, 0}; lv_point_t p = {0, 0};
scroll_area_into_view(&obj->coords, obj, &p, anim_en); scroll_area_into_view(&obj->coords, obj, &p, anim_en);
@@ -342,7 +342,7 @@ void lv_obj_scroll_to_view(lv_obj_t * obj, lv_anim_enable_t anim_en)
void lv_obj_scroll_to_view_recursive(lv_obj_t * obj, lv_anim_enable_t anim_en) void lv_obj_scroll_to_view_recursive(lv_obj_t * obj, lv_anim_enable_t anim_en)
{ {
/*Be sure the screens layout is correct*/ /*Be sure the screens layout is correct*/
lv_obj_update_layout(lv_obj_get_screen(obj)); lv_obj_update_layout(obj);
lv_point_t p = {0, 0}; lv_point_t p = {0, 0};
lv_obj_t * child = obj; lv_obj_t * child = obj;

View File

@@ -223,6 +223,22 @@ void lv_obj_set_local_style_prop(lv_obj_t * obj, uint32_t part, uint32_t state,
lv_obj_refresh_style(obj, part, prop); lv_obj_refresh_style(obj, part, prop);
} }
lv_res_t lv_obj_get_local_style_prop(lv_obj_t * obj, uint32_t part, uint32_t state, lv_style_prop_t prop, lv_style_value_t * value)
{
uint32_t i;
for(i = 0; i < obj->style_cnt; i++) {
if(obj->styles[i].is_local &&
obj->styles[i].part == part &&
obj->styles[i].state == state)
{
return lv_style_get_prop(obj->styles[i].style, prop, value);
}
}
return LV_RES_INV;
}
bool lv_obj_remove_local_style_prop(lv_obj_t * obj, uint32_t part, uint32_t state, lv_style_prop_t prop) bool lv_obj_remove_local_style_prop(lv_obj_t * obj, uint32_t part, uint32_t state, lv_style_prop_t prop)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
@@ -416,6 +432,7 @@ static lv_style_t * get_local_style(lv_obj_t * obj, uint32_t part, uint32_t stat
obj->style_cnt++; obj->style_cnt++;
obj->styles = lv_mem_realloc(obj->styles, obj->style_cnt * sizeof(lv_obj_style_t)); obj->styles = lv_mem_realloc(obj->styles, obj->style_cnt * sizeof(lv_obj_style_t));
LV_ASSERT_MALLOC(obj->styles);
for(i = obj->style_cnt - 1; i > 0 ; i--) { for(i = obj->style_cnt - 1; i > 0 ; i--) {
/*Copy only normal styles (not local and transition). /*Copy only normal styles (not local and transition).

View File

@@ -128,6 +128,8 @@ lv_style_value_t lv_obj_get_style_prop(const struct _lv_obj_t * obj, uint8_t par
*/ */
void lv_obj_set_local_style_prop(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_style_prop_t prop, lv_style_value_t value); void lv_obj_set_local_style_prop(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_style_prop_t prop, lv_style_value_t value);
lv_res_t lv_obj_get_local_style_prop(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_style_prop_t prop, lv_style_value_t * value);
/** /**
* Remove a local style property from a part of an object with a given state. * Remove a local style property from a part of an object with a given state.
* @param obj pointer to an object * @param obj pointer to an object

View File

@@ -112,6 +112,37 @@ static inline lv_coord_t lv_obj_get_style_pad_column(const struct _lv_obj_t * ob
return (lv_coord_t)v.num; return (lv_coord_t)v.num;
} }
static inline lv_coord_t lv_obj_get_style_width(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_WIDTH);
return (lv_coord_t)v.num;
}
static inline lv_coord_t lv_obj_get_style_height(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_HEIGHT);
return (lv_coord_t)v.num;
}
static inline lv_coord_t lv_obj_get_style_x(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_X);
return (lv_coord_t)v.num;
}
static inline lv_coord_t lv_obj_get_style_y(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_Y);
return (lv_coord_t)v.num;
}
static inline lv_coord_t lv_obj_get_style_layout(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LAYOUT);
return (lv_coord_t)v.num;
}
static inline lv_color_t lv_obj_get_style_bg_color(const struct _lv_obj_t * obj, uint32_t part) static inline lv_color_t lv_obj_get_style_bg_color(const struct _lv_obj_t * obj, uint32_t part)
{ {
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_COLOR); lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_BG_COLOR);
@@ -672,6 +703,46 @@ static inline void lv_obj_set_style_pad_column(struct _lv_obj_t * obj, uint32_t
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_PAD_COLUMN, v); lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_PAD_COLUMN, v);
} }
static inline void lv_obj_set_style_width(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_WIDTH, v);
}
static inline void lv_obj_set_style_height(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_HEIGHT, v);
}
static inline void lv_obj_set_style_x(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_X, v);
}
static inline void lv_obj_set_style_y(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_Y, v);
}
static inline void lv_obj_set_style_layout(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_LAYOUT, v);
}
static inline void lv_obj_set_style_bg_color(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_color_t value) static inline void lv_obj_set_style_bg_color(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_color_t value)
{ {
lv_style_value_t v = { lv_style_value_t v = {

View File

@@ -64,7 +64,7 @@ void lv_obj_del(lv_obj_t * obj)
obj_del_core(obj); obj_del_core(obj);
/*Send a Call the ancestor's event handler to the parent to notify it about the child delete*/ /*Call the ancestor's event handler to the parent to notify it about the child delete*/
if(par) { if(par) {
/*Just to remove scroll animations if any*/ /*Just to remove scroll animations if any*/
lv_obj_scroll_to(par, 0, 0, LV_ANIM_OFF); lv_obj_scroll_to(par, 0, 0, LV_ANIM_OFF);

View File

@@ -197,10 +197,8 @@ void _lv_disp_refr_timer(lv_timer_t * tmr)
#endif #endif
/*Refresh the screen's layout if required*/ /*Refresh the screen's layout if required*/
uint32_t i; lv_obj_update_layout(disp_refr->act_scr);
for(i = 0; i < disp_refr->screen_cnt; i++) { if(disp_refr->prev_scr) lv_obj_update_layout(disp_refr->prev_scr);
lv_obj_update_layout(disp_refr->screens[i]);
}
lv_obj_update_layout(disp_refr->top_layer); lv_obj_update_layout(disp_refr->top_layer);
lv_obj_update_layout(disp_refr->sys_layer); lv_obj_update_layout(disp_refr->sys_layer);

View File

@@ -49,14 +49,9 @@ void lv_theme_apply(lv_obj_t * obj)
lv_theme_t * th = lv_theme_get_from_obj(obj); lv_theme_t * th = lv_theme_get_from_obj(obj);
if(th == NULL) return; if(th == NULL) return;
lv_obj_enable_style_refresh(false);
lv_obj_remove_style(obj, LV_PART_ANY, LV_STATE_ANY, NULL); lv_obj_remove_style(obj, LV_PART_ANY, LV_STATE_ANY, NULL);
apply_theme(th, obj); /*Apply the theme including the base theme(s)*/ apply_theme(th, obj); /*Apply the theme including the base theme(s)*/
lv_obj_enable_style_refresh(true);
lv_obj_refresh_style(obj, LV_PART_ANY, LV_STYLE_PROP_ALL);
} }
/** /**

View File

@@ -17,6 +17,15 @@
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
typedef struct {
lv_flex_place_t main_place;
lv_flex_place_t cross_place;
lv_flex_place_t track_place;
uint8_t row :1;
uint8_t wrap :1;
uint8_t rev :1;
}flex_t;
typedef struct { typedef struct {
lv_coord_t grow_unit; lv_coord_t grow_unit;
lv_coord_t track_cross_size; lv_coord_t track_cross_size;
@@ -33,66 +42,20 @@ typedef struct {
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static void flex_update(lv_obj_t * cont); static void flex_update(lv_obj_t * cont);
static int32_t find_track_end(lv_obj_t * cont, int32_t item_start_id, lv_coord_t item_gap, lv_coord_t max_main_size, track_t * t); static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id, lv_coord_t item_gap, lv_coord_t max_main_size, track_t * t);
static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_last_id, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t); static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, int32_t item_last_id, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t);
static void place_content(lv_flex_place_t place, lv_coord_t max_size, lv_coord_t content_size, lv_coord_t item_cnt, lv_coord_t * start_pos, lv_coord_t * gap); static void place_content(lv_flex_place_t place, lv_coord_t max_size, lv_coord_t content_size, lv_coord_t item_cnt, lv_coord_t * start_pos, lv_coord_t * gap);
static lv_obj_t * get_next_item(lv_obj_t * cont, bool rev, int32_t * item_id); static lv_obj_t * get_next_item(lv_obj_t * cont, bool rev, int32_t * item_id);
/********************** /**********************
* GLOBAL VARIABLES * GLOBAL VARIABLES
**********************/ **********************/
uint32_t LV_LAYOUT_FLEX;
const lv_flex_t lv_flex_row_center = { lv_style_prop_t LV_STYLE_FLEX_FLOW;
.base.update_cb = flex_update, lv_style_prop_t LV_STYLE_FLEX_MAIN_PLACE;
.main_place = LV_FLEX_PLACE_CENTER, lv_style_prop_t LV_STYLE_FLEX_CROSS_PLACE;
.cross_place = LV_FLEX_PLACE_CENTER, lv_style_prop_t LV_STYLE_FLEX_TRACK_PLACE;
.track_place = LV_FLEX_PLACE_CENTER, lv_style_prop_t LV_STYLE_FLEX_GROW;
.dir = LV_FLEX_FLOW_ROW,
.wrap = 1
};
const lv_flex_t lv_flex_column_center = {
.base.update_cb = flex_update,
.main_place = LV_FLEX_PLACE_CENTER,
.cross_place = LV_FLEX_PLACE_CENTER,
.track_place = LV_FLEX_PLACE_CENTER,
.dir = LV_FLEX_FLOW_COLUMN,
.wrap = 1
};
const lv_flex_t lv_flex_row_wrap = {
.base.update_cb = flex_update,
.main_place = LV_FLEX_PLACE_START,
.cross_place = LV_FLEX_PLACE_CENTER,
.track_place = LV_FLEX_PLACE_START,
.dir = LV_FLEX_FLOW_ROW,
.wrap = 1
};
const lv_flex_t lv_flex_row_even = {
.base.update_cb = flex_update,
.main_place = LV_FLEX_PLACE_SPACE_EVENLY,
.cross_place = LV_FLEX_PLACE_CENTER,
.track_place = LV_FLEX_PLACE_CENTER,
.dir = LV_FLEX_FLOW_ROW,
.wrap = 1
};
const lv_flex_t lv_flex_column_nowrap = {
.base.update_cb = flex_update,
.main_place = LV_FLEX_PLACE_START,
.cross_place = LV_FLEX_PLACE_CENTER,
.track_place = LV_FLEX_PLACE_START,
.dir = LV_FLEX_FLOW_COLUMN
};
const lv_flex_t lv_flex_row_nowrap = {
.base.update_cb = flex_update,
.main_place = LV_FLEX_PLACE_START,
.cross_place = LV_FLEX_PLACE_CENTER,
.track_place = LV_FLEX_PLACE_START,
.dir = LV_FLEX_FLOW_ROW
};
/********************** /**********************
@@ -111,41 +74,33 @@ const lv_flex_t lv_flex_row_nowrap = {
* Setter functions * Setter functions
*====================*/ *====================*/
void lv_flex_init(lv_flex_t * flex) void lv_flex_init(void)
{ {
lv_memset_00(flex, sizeof(lv_flex_t)); LV_LAYOUT_FLEX = lv_layout_register(flex_update);
flex->base.update_cb = flex_update;
flex->dir = LV_FLEX_FLOW_ROW; LV_STYLE_FLEX_FLOW = lv_style_register_prop();
flex->main_place = LV_FLEX_PLACE_START; LV_STYLE_FLEX_MAIN_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR;
flex->track_place = LV_FLEX_PLACE_START; LV_STYLE_FLEX_CROSS_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR;
flex->cross_place = LV_FLEX_PLACE_START; LV_STYLE_FLEX_TRACK_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR;
} }
void lv_flex_set_flow(lv_flex_t * flex, lv_flex_flow_t flow) void lv_obj_set_flex_flow(lv_obj_t * obj, lv_flex_flow_t flow)
{ {
flex->dir = flow & 0x3; lv_obj_set_style_flex_flow(obj, LV_PART_MAIN, LV_STATE_DEFAULT, flow);
flex->wrap = flow & _LV_FLEX_WRAP ? 1 : 0; lv_obj_set_style_layout(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_LAYOUT_FLEX);
flex->rev = flow & _LV_FLEX_REVERSE ? 1 : 0;
} }
void lv_flex_set_place(lv_flex_t * flex, lv_flex_place_t main_place, lv_flex_place_t cross_place, lv_flex_place_t track_place) void lv_obj_set_flex_place(lv_obj_t * obj, lv_flex_place_t main_place, lv_flex_place_t cross_place, lv_flex_place_t track_place)
{ {
flex->main_place = main_place; lv_obj_set_style_flex_main_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, main_place);
flex->cross_place = cross_place; lv_obj_set_style_flex_cross_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, cross_place);
flex->track_place = track_place; lv_obj_set_style_flex_track_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, track_place);
lv_obj_set_style_layout(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_LAYOUT_FLEX);
} }
void lv_obj_set_flex_grow(struct _lv_obj_t * obj, uint8_t grow) void lv_obj_set_flex_grow(struct _lv_obj_t * obj, uint8_t grow)
{ {
if(!lv_obj_is_layout_positioned(obj)) return; lv_obj_set_style_flex_grow(obj, LV_PART_MAIN, LV_STATE_DEFAULT, grow);
lv_obj_t * parent = lv_obj_get_parent(obj);
if(parent->spec_attr->layout_dsc->update_cb != flex_update) return;
const lv_flex_t * f = (const lv_flex_t *)parent->spec_attr->layout_dsc;
if(f->dir == LV_FLEX_FLOW_ROW) lv_obj_set_width(obj, (LV_COORD_SET_LAYOUT(grow)));
else lv_obj_set_height(obj, (LV_COORD_SET_LAYOUT(grow)));
lv_obj_mark_layout_as_dirty(parent);
} }
/********************** /**********************
@@ -154,29 +109,37 @@ void lv_obj_set_flex_grow(struct _lv_obj_t * obj, uint8_t grow)
static void flex_update(lv_obj_t * cont) static void flex_update(lv_obj_t * cont)
{ {
if(cont->spec_attr == NULL) return;
const lv_flex_t * f = (const lv_flex_t *)cont->spec_attr->layout_dsc;
LV_LOG_INFO("update %p container", cont); LV_LOG_INFO("update %p container", cont);
flex_t f;
lv_flex_flow_t flow = lv_obj_get_style_flex_flow(cont, LV_PART_MAIN);
f.row = flow & _LV_FLEX_COLUMN ? 0 : 1;
f.wrap = flow & _LV_FLEX_WRAP ? 1 : 0;
f.rev = flow & _LV_FLEX_REVERSE ? 1 : 0;
f.main_place = lv_obj_get_style_flex_main_place(cont, LV_PART_MAIN);
f.cross_place = lv_obj_get_style_flex_cross_place(cont, LV_PART_MAIN);
f.track_place = lv_obj_get_style_flex_track_place(cont, LV_PART_MAIN);
bool rtl = lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL ? true : false; bool rtl = lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL ? true : false;
bool row = f->dir == LV_FLEX_FLOW_ROW ? true : false; lv_coord_t track_gap = !f.row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont, LV_PART_MAIN);
lv_coord_t track_gap = !row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont, LV_PART_MAIN); lv_coord_t item_gap = f.row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont, LV_PART_MAIN);
lv_coord_t item_gap = row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont, LV_PART_MAIN); lv_coord_t max_main_size = (f.row ? lv_obj_get_width_fit(cont) : lv_obj_get_height_fit(cont));
lv_coord_t max_main_size = (row ? lv_obj_get_width_fit(cont) : lv_obj_get_height_fit(cont));
lv_coord_t abs_y = cont->coords.y1 + lv_obj_get_style_pad_top(cont, LV_PART_MAIN) - lv_obj_get_scroll_y(cont); lv_coord_t abs_y = cont->coords.y1 + lv_obj_get_style_pad_top(cont, LV_PART_MAIN) - lv_obj_get_scroll_y(cont);
lv_coord_t abs_x = cont->coords.x1 + lv_obj_get_style_pad_left(cont, LV_PART_MAIN) - lv_obj_get_scroll_x(cont); lv_coord_t abs_x = cont->coords.x1 + lv_obj_get_style_pad_left(cont, LV_PART_MAIN) - lv_obj_get_scroll_x(cont);
lv_flex_place_t track_cross_place = f->track_place; lv_flex_place_t track_cross_place = f.track_place;
lv_coord_t * cross_pos = (row ? &abs_y : &abs_x); lv_coord_t * cross_pos = (f.row ? &abs_y : &abs_x);
if((row && cont->h_set == LV_SIZE_CONTENT) || lv_coord_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN);
(!row && cont->w_set == LV_SIZE_CONTENT)) lv_coord_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN);
if((f.row && h_set == LV_SIZE_CONTENT) ||
(!f.row && w_set == LV_SIZE_CONTENT))
{ {
track_cross_place = LV_FLEX_PLACE_START; track_cross_place = LV_FLEX_PLACE_START;
} }
if(rtl && !row) { if(rtl && !f.row) {
if(track_cross_place == LV_FLEX_PLACE_START) track_cross_place = LV_FLEX_PLACE_END; if(track_cross_place == LV_FLEX_PLACE_START) track_cross_place = LV_FLEX_PLACE_END;
else if(track_cross_place == LV_FLEX_PLACE_END) track_cross_place = LV_FLEX_PLACE_START; else if(track_cross_place == LV_FLEX_PLACE_END) track_cross_place = LV_FLEX_PLACE_START;
} }
@@ -188,11 +151,11 @@ static void flex_update(lv_obj_t * cont)
int32_t next_track_first_item; int32_t next_track_first_item;
if(track_cross_place != LV_FLEX_PLACE_START) { if(track_cross_place != LV_FLEX_PLACE_START) {
track_first_item = f->rev ? cont->spec_attr->child_cnt - 1 : 0; track_first_item = f.rev ? cont->spec_attr->child_cnt - 1 : 0;
track_t t; track_t t;
while(track_first_item < (int32_t)cont->spec_attr->child_cnt && track_first_item >= 0) { while(track_first_item < (int32_t)cont->spec_attr->child_cnt && track_first_item >= 0) {
/*Search the first item of the next row*/ /*Search the first item of the next row*/
next_track_first_item = find_track_end(cont, track_first_item, max_main_size, item_gap, &t); next_track_first_item = find_track_end(cont, &f, track_first_item, max_main_size, item_gap, &t);
total_track_cross_size += t.track_cross_size + track_gap; total_track_cross_size += t.track_cross_size + track_gap;
track_cnt++; track_cnt++;
track_first_item = next_track_first_item; track_first_item = next_track_first_item;
@@ -201,28 +164,28 @@ static void flex_update(lv_obj_t * cont)
if(track_cnt) total_track_cross_size -= track_gap; /*No gap after the last track*/ if(track_cnt) total_track_cross_size -= track_gap; /*No gap after the last track*/
/*Place the tracks to get the start position*/ /*Place the tracks to get the start position*/
lv_coord_t max_cross_size = (row ? lv_obj_get_height_fit(cont) : lv_obj_get_width_fit(cont)); lv_coord_t max_cross_size = (f.row ? lv_obj_get_height_fit(cont) : lv_obj_get_width_fit(cont));
place_content(track_cross_place, max_cross_size, total_track_cross_size, track_cnt, cross_pos, &gap); place_content(track_cross_place, max_cross_size, total_track_cross_size, track_cnt, cross_pos, &gap);
} }
track_first_item = f->rev ? cont->spec_attr->child_cnt - 1 : 0; track_first_item = f.rev ? cont->spec_attr->child_cnt - 1 : 0;
if(rtl && !row) { if(rtl && !f.row) {
*cross_pos += total_track_cross_size; *cross_pos += total_track_cross_size;
} }
while(track_first_item < (int32_t)cont->spec_attr->child_cnt && track_first_item >= 0) { while(track_first_item < (int32_t)cont->spec_attr->child_cnt && track_first_item >= 0) {
track_t t; track_t t;
/*Search the first item of the next row*/ /*Search the first item of the next row*/
next_track_first_item = find_track_end(cont, track_first_item, max_main_size, item_gap, &t); next_track_first_item = find_track_end(cont, &f, track_first_item, max_main_size, item_gap, &t);
if(rtl && !row) { if(rtl && !f.row) {
*cross_pos -= t.track_cross_size; *cross_pos -= t.track_cross_size;
} }
children_repos(cont, track_first_item, next_track_first_item, abs_x, abs_y, max_main_size, item_gap, &t); children_repos(cont, &f, track_first_item, next_track_first_item, abs_x, abs_y, max_main_size, item_gap, &t);
track_first_item = next_track_first_item; track_first_item = next_track_first_item;
if(rtl && !row) { if(rtl && !f.row) {
*cross_pos -= gap + track_gap; *cross_pos -= gap + track_gap;
} else { } else {
*cross_pos += t.track_cross_size + gap + track_gap; *cross_pos += t.track_cross_size + gap + track_gap;
@@ -230,8 +193,8 @@ static void flex_update(lv_obj_t * cont)
} }
LV_ASSERT_MEM_INTEGRITY(); LV_ASSERT_MEM_INTEGRITY();
if(cont->w_set == LV_SIZE_CONTENT || cont->h_set == LV_SIZE_CONTENT) { if(w_set == LV_SIZE_CONTENT || h_set == LV_SIZE_CONTENT) {
lv_obj_set_size(cont, cont->w_set, cont->h_set); lv_obj_refr_size(cont);
} }
LV_TRACE_LAYOUT("finished"); LV_TRACE_LAYOUT("finished");
@@ -240,18 +203,17 @@ static void flex_update(lv_obj_t * cont)
/** /**
* Find the last item of a track * Find the last item of a track
*/ */
static int32_t find_track_end(lv_obj_t * cont, int32_t item_start_id, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t) static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t)
{ {
const lv_flex_t * f = (const lv_flex_t *)cont->spec_attr->layout_dsc; lv_coord_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN);
lv_coord_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN);
bool row = f->dir == LV_FLEX_FLOW_ROW ? true : false;
bool wrap = f->wrap;
/*Can't wrap if the size if auto (i.e. the size depends on the children)*/ /*Can't wrap if the size if auto (i.e. the size depends on the children)*/
if(wrap && ((row && cont->w_set == LV_SIZE_CONTENT) || (!row && cont->h_set == LV_SIZE_CONTENT))) { if(f->wrap && ((f->row && w_set == LV_SIZE_CONTENT) || (!f->row && h_set == LV_SIZE_CONTENT))) {
wrap = false; f->wrap = false;
} }
lv_coord_t(*get_main_size)(const lv_obj_t *) = (row ? lv_obj_get_width : lv_obj_get_height); lv_coord_t(*get_main_size)(const lv_obj_t *) = (f->row ? lv_obj_get_width : lv_obj_get_height);
lv_coord_t(*get_cross_size)(const lv_obj_t *) = (!row ? lv_obj_get_width : lv_obj_get_height); lv_coord_t(*get_cross_size)(const lv_obj_t *) = (!f->row ? lv_obj_get_width : lv_obj_get_height);
lv_coord_t grow_sum = 0; lv_coord_t grow_sum = 0;
t->track_main_size = 0; t->track_main_size = 0;
@@ -267,14 +229,14 @@ static int32_t find_track_end(lv_obj_t * cont, int32_t item_start_id, lv_coord_t
if(item_id != item_start_id && lv_obj_has_flag(item, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK)) break; if(item_id != item_start_id && lv_obj_has_flag(item, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK)) break;
if(!lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) { if(!lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) {
lv_coord_t main_size = (row ? item->w_set : item->h_set); uint8_t grow_size = lv_obj_get_style_flex_grow(item, LV_PART_MAIN);
if(_LV_FLEX_GET_GROW(main_size)) { if(grow_size) {
grow_sum += _LV_FLEX_GET_GROW(main_size); grow_sum += grow_size;
grow_item_cnt++; grow_item_cnt++;
t->track_main_size += item_gap; t->track_main_size += item_gap;
} else { } else {
lv_coord_t item_size = get_main_size(item); lv_coord_t item_size = get_main_size(item);
if(wrap && t->track_main_size + item_size > max_main_size) break; if(f->wrap && t->track_main_size + item_size > max_main_size) break;
t->track_main_size += item_size + item_gap; t->track_main_size += item_size + item_gap;
} }
@@ -315,14 +277,11 @@ static int32_t find_track_end(lv_obj_t * cont, int32_t item_start_id, lv_coord_t
/** /**
* Position the children in the same track * Position the children in the same track
*/ */
static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_last_id, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t) static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, int32_t item_last_id, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t)
{ {
const lv_flex_t * f = (const lv_flex_t *)cont->spec_attr->layout_dsc; void (*area_set_main_size)(lv_area_t *, lv_coord_t) = (f->row ? lv_area_set_width : lv_area_set_height);
bool row = f->dir == LV_FLEX_FLOW_ROW ? true : false; lv_coord_t (*area_get_main_size)(const lv_area_t *) = (f->row ? lv_area_get_width : lv_area_get_height);
lv_coord_t (*area_get_cross_size)(const lv_area_t *) = (!f->row ? lv_area_get_width : lv_area_get_height);
void (*area_set_main_size)(lv_area_t *, lv_coord_t) = (row ? lv_area_set_width : lv_area_set_height);
lv_coord_t (*area_get_main_size)(const lv_area_t *) = (row ? lv_area_get_width : lv_area_get_height);
lv_coord_t (*area_get_cross_size)(const lv_area_t *) = (!row ? lv_area_get_width : lv_area_get_height);
bool rtl = lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL ? true : false; bool rtl = lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL ? true : false;
@@ -330,7 +289,7 @@ static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_
lv_coord_t place_gap = 0; lv_coord_t place_gap = 0;
place_content(f->main_place, max_main_size, t->track_main_size, t->item_cnt, &main_pos, &place_gap); place_content(f->main_place, max_main_size, t->track_main_size, t->item_cnt, &main_pos, &place_gap);
if(row && rtl) main_pos += t->track_main_size; if(f->row && rtl) main_pos += t->track_main_size;
lv_obj_t * item = lv_obj_get_child(cont, item_first_id); lv_obj_t * item = lv_obj_get_child(cont, item_first_id);
/*Reposition the children*/ /*Reposition the children*/
@@ -339,19 +298,26 @@ static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_
item = get_next_item(cont, f->rev, &item_first_id); item = get_next_item(cont, f->rev, &item_first_id);
continue; continue;
} }
lv_coord_t main_size = (row ? item->w_set : item->h_set); uint8_t grow_size = lv_obj_get_style_flex_grow(item, LV_PART_MAIN);
if(_LV_FLEX_GET_GROW(main_size)) { if(grow_size) {
lv_area_t old_coords; lv_area_t old_coords;
lv_area_copy(&old_coords, &item->coords); lv_area_copy(&old_coords, &item->coords);
lv_coord_t s = _LV_FLEX_GET_GROW(main_size) * t->grow_unit; lv_coord_t s = grow_size * t->grow_unit;
area_set_main_size(&item->coords, s); area_set_main_size(&item->coords, s);
if(lv_area_get_height(&old_coords) != area_get_main_size(&item->coords)) { if(f->row) item->w_layout = 1;
else item->h_layout = 1;
if(area_get_main_size(&old_coords) != area_get_main_size(&item->coords)) {
lv_obj_invalidate(item); lv_obj_invalidate(item);
lv_event_send(item, LV_EVENT_COORD_CHANGED, &old_coords); lv_event_send(item, LV_EVENT_SIZE_CHANGED, &old_coords);
lv_event_send(lv_obj_get_parent(item), LV_EVENT_CHILD_CHANGED, item);
lv_obj_invalidate(item); lv_obj_invalidate(item);
} }
} else {
item->w_layout = 0;
item->h_layout = 0;
} }
lv_coord_t cross_pos = 0; lv_coord_t cross_pos = 0;
@@ -368,13 +334,13 @@ static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_
break; break;
} }
if(row && rtl) main_pos -= area_get_main_size(&item->coords); if(f->row && rtl) main_pos -= area_get_main_size(&item->coords);
lv_coord_t diff_x = abs_x - item->coords.x1; lv_coord_t diff_x = abs_x - item->coords.x1;
lv_coord_t diff_y = abs_y - item->coords.y1; lv_coord_t diff_y = abs_y - item->coords.y1;
diff_x += row ? main_pos : cross_pos; diff_x += f->row ? main_pos : cross_pos;
diff_y += row ? cross_pos : main_pos; diff_y += f->row ? cross_pos : main_pos;
if(diff_x || diff_y) { if(diff_x || diff_y) {
lv_obj_invalidate(item); lv_obj_invalidate(item);
@@ -386,7 +352,7 @@ static void children_repos(lv_obj_t * cont, int32_t item_first_id, int32_t item_
lv_obj_move_children_by(item, diff_x, diff_y, true); lv_obj_move_children_by(item, diff_x, diff_y, true);
} }
if(!(row && rtl)) main_pos += area_get_main_size(&item->coords) + item_gap + place_gap; if(!(f->row && rtl)) main_pos += area_get_main_size(&item->coords) + item_gap + place_gap;
else main_pos -= item_gap + place_gap; else main_pos -= item_gap + place_gap;
item = get_next_item(cont, f->rev, &item_first_id); item = get_next_item(cont, f->rev, &item_first_id);

View File

@@ -19,14 +19,14 @@ extern "C" {
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
#define _LV_FLEX_GET_GROW(v) (LV_COORD_IS_LAYOUT(v) ? _LV_COORD_PLAIN(v) : 0)
#define _LV_FLEX_WRAP (1 << 2)
#define _LV_FLEX_REVERSE (1 << 3)
#define LV_OBJ_FLAG_FLEX_IN_NEW_TRACK LV_OBJ_FLAG_LAYOUT_1 #define LV_OBJ_FLAG_FLEX_IN_NEW_TRACK LV_OBJ_FLAG_LAYOUT_1
LV_EXPORT_CONST_INT(LV_OBJ_FLAG_FLEX_IN_NEW_TRACK); LV_EXPORT_CONST_INT(LV_OBJ_FLAG_FLEX_IN_NEW_TRACK);
#define _LV_FLEX_COLUMN (1 << 0)
#define _LV_FLEX_WRAP (1 << 2)
#define _LV_FLEX_REVERSE (1 << 3)
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
@@ -35,7 +35,6 @@ LV_EXPORT_CONST_INT(LV_OBJ_FLAG_FLEX_IN_NEW_TRACK);
struct _lv_obj_t; struct _lv_obj_t;
typedef enum { typedef enum {
LV_FLEX_PLACE_NONE,
LV_FLEX_PLACE_START, LV_FLEX_PLACE_START,
LV_FLEX_PLACE_END, LV_FLEX_PLACE_END,
LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_CENTER,
@@ -45,8 +44,8 @@ typedef enum {
}lv_flex_place_t; }lv_flex_place_t;
typedef enum { typedef enum {
LV_FLEX_FLOW_ROW = 0x01, LV_FLEX_FLOW_ROW = 0x00,
LV_FLEX_FLOW_COLUMN = 0x02, LV_FLEX_FLOW_COLUMN = _LV_FLEX_COLUMN,
LV_FLEX_FLOW_ROW_WRAP = LV_FLEX_FLOW_ROW | _LV_FLEX_WRAP, LV_FLEX_FLOW_ROW_WRAP = LV_FLEX_FLOW_ROW | _LV_FLEX_WRAP,
LV_FLEX_FLOW_ROW_REVERSE = LV_FLEX_FLOW_ROW | _LV_FLEX_REVERSE, LV_FLEX_FLOW_ROW_REVERSE = LV_FLEX_FLOW_ROW | _LV_FLEX_REVERSE,
LV_FLEX_FLOW_ROW_WRAP_REVERSE = LV_FLEX_FLOW_ROW | _LV_FLEX_WRAP | _LV_FLEX_REVERSE, LV_FLEX_FLOW_ROW_WRAP_REVERSE = LV_FLEX_FLOW_ROW | _LV_FLEX_WRAP | _LV_FLEX_REVERSE,
@@ -55,15 +54,15 @@ typedef enum {
LV_FLEX_FLOW_COLUMN_WRAP_REVERSE = LV_FLEX_FLOW_COLUMN | _LV_FLEX_WRAP | _LV_FLEX_REVERSE, LV_FLEX_FLOW_COLUMN_WRAP_REVERSE = LV_FLEX_FLOW_COLUMN | _LV_FLEX_WRAP | _LV_FLEX_REVERSE,
}lv_flex_flow_t; }lv_flex_flow_t;
typedef struct { /**********************
lv_layout_dsc_t base; * GLOBAL VARIABLES
uint32_t dir :2; **********************/
uint32_t wrap :1; extern uint32_t LV_LAYOUT_FLEX;
uint32_t rev :1; extern lv_style_prop_t LV_STYLE_FLEX_FLOW;
uint32_t main_place :3; extern lv_style_prop_t LV_STYLE_FLEX_MAIN_PLACE;
uint32_t track_place :3; extern lv_style_prop_t LV_STYLE_FLEX_CROSS_PLACE;
uint32_t cross_place :3; extern lv_style_prop_t LV_STYLE_FLEX_TRACK_PLACE;
}lv_flex_t; extern lv_style_prop_t LV_STYLE_FLEX_GROW;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
@@ -73,14 +72,14 @@ typedef struct {
* Initialize a felx layout the default values * Initialize a felx layout the default values
* @param flex pointer to a flex layout descriptor * @param flex pointer to a flex layout descriptor
*/ */
void lv_flex_init(lv_flex_t * flex); void lv_flex_init(void);
/** /**
* Set hot the item should flow * Set hot the item should flow
* @param flex pointer to a flex layout descriptor * @param flex pointer to a flex layout descriptor
* @param flow an element of `lv_flex_flow_t`. * @param flow an element of `lv_flex_flow_t`.
*/ */
void lv_flex_set_flow(lv_flex_t * flex, lv_flex_flow_t flow); void lv_obj_set_flex_flow(lv_obj_t * obj, lv_flex_flow_t flow);
/** /**
* Set how to place (where to align) the items an tracks * Set how to place (where to align) the items an tracks
@@ -89,28 +88,129 @@ void lv_flex_set_flow(lv_flex_t * flex, lv_flex_flow_t flow);
* @param cross_place where to place the item in their track on the cross axis. `LV_FLEX_PLACE_START/END/CENTER` * @param cross_place where to place the item in their track on the cross axis. `LV_FLEX_PLACE_START/END/CENTER`
* @param track_place where to place the tracks in the cross direction. Any value of `lv_flex_place_t`. * @param track_place where to place the tracks in the cross direction. Any value of `lv_flex_place_t`.
*/ */
void lv_flex_set_place(lv_flex_t * flex, lv_flex_place_t main_place, lv_flex_place_t cross_place, lv_flex_place_t track_cross_place); void lv_obj_set_flex_place(lv_obj_t * obj, lv_flex_place_t main_place, lv_flex_place_t cross_place, lv_flex_place_t track_cross_place);
/** /**
* Sets the width or height (on main axis) to grow the object in order fill the free space * Sets the width or height (on main axis) to grow the object in order fill the free space
* @param obj pointer to an object. The parent must have flex layout else nothing will happen. * @param obj pointer to an object. The parent must have flex layout else nothing will happen.
* @param grow a value to set how much free space to take proportionally to other growing items. * @param grow a value to set how much free space to take proportionally to other growing items.
*/ */
void lv_obj_set_flex_grow(struct _lv_obj_t * obj, uint8_t grow); void lv_obj_set_flex_grow(lv_obj_t * obj, uint8_t grow);
/**********************
* GLOBAL VARIABLES
**********************/
/**
* Predefines flex layouts static inline void lv_style_set_flex_flow(lv_style_t * style, lv_flex_flow_t value)
*/ {
extern const lv_flex_t lv_flex_row_wrap; /**< Just put the items next to each other with wrap*/ lv_style_value_t v = {
extern const lv_flex_t lv_flex_row_center; /**< Center in a row with wrap*/ .num = (int32_t)value
extern const lv_flex_t lv_flex_column_center; /**< Center in a column with wrap*/ };
extern const lv_flex_t lv_flex_column_nowrap; /**< Stack the items vertically without wrapping*/ lv_style_set_prop(style, LV_STYLE_FLEX_FLOW, v);
extern const lv_flex_t lv_flex_row_nowrap; /**< Put the items next to each other without wrap*/ }
extern const lv_flex_t lv_flex_row_even; /**< Place the items evenly in row with wrapping and vertical centering*/
static inline void lv_style_set_flex_main_place(lv_style_t * style, lv_flex_place_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_FLEX_MAIN_PLACE, v);
}
static inline void lv_style_set_flex_cross_place(lv_style_t * style, lv_flex_place_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_FLEX_CROSS_PLACE, v);
}
static inline void lv_style_set_flex_track_place(lv_style_t * style, lv_flex_place_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_FLEX_TRACK_PLACE, v);
}
static inline void lv_style_set_flex_grow(lv_style_t * style, uint8_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_FLEX_GROW, v);
}
static inline void lv_obj_set_style_flex_flow(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_flex_flow_t value)
{
lv_style_value_t v = {
.num = (int32_t) value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_FLEX_FLOW, v);
}
static inline void lv_obj_set_style_flex_main_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_flex_place_t value)
{
lv_style_value_t v = {
.num = (int32_t) value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_FLEX_MAIN_PLACE, v);
}
static inline void lv_obj_set_style_flex_cross_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_flex_place_t value)
{
lv_style_value_t v = {
.num = (int32_t) value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_FLEX_CROSS_PLACE, v);
}
static inline void lv_obj_set_style_flex_track_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_flex_place_t value)
{
lv_style_value_t v = {
.num = (int32_t) value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_FLEX_TRACK_PLACE, v);
}
static inline void lv_obj_set_style_flex_grow(lv_obj_t * obj, lv_part_t part, lv_state_t state, uint8_t value)
{
lv_style_value_t v = {
.num = (int32_t) value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_FLEX_GROW, v);
}
static inline lv_flex_flow_t lv_obj_get_style_flex_flow(const lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_FLOW);
return (lv_flex_flow_t)v.num;
}
static inline lv_flex_place_t lv_obj_get_style_flex_main_place(const lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_MAIN_PLACE);
return (lv_flex_place_t)v.num;
}
static inline lv_flex_place_t lv_obj_get_style_flex_cross_place(const lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_CROSS_PLACE);
return (lv_flex_place_t)v.num;
}
static inline lv_flex_place_t lv_obj_get_style_flex_track_place(const lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_TRACK_PLACE);
return (lv_flex_place_t)v.num;
}
static inline uint8_t lv_obj_get_style_flex_grow(const lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_GROW);
return (uint8_t)v.num;
}
/********************** /**********************
* MACROS * MACROS

View File

@@ -16,15 +16,9 @@
/** /**
* Some helper defines * Some helper defines
*/ */
#define CELL_SHIFT 4 #define IS_FR(x) (x >= LV_COORD_MAX - 100)
#define CELL_POS_MASK ((1 << CELL_SHIFT) - 1) #define IS_CONTENT(x) (x == LV_COORD_MAX - 101)
#define CELL_SPAN_MASK (CELL_POS_MASK << CELL_SHIFT) #define GET_FR(x) (x - (LV_COORD_MAX - 100))
#define CELL_FLAG_MASK (CELL_POS_MASK << (2 * CELL_SHIFT))
#define IS_FR(x) (LV_COORD_IS_LAYOUT(x) && _LV_COORD_PLAIN(x) < 100)
#define IS_CONTENT(x) (LV_COORD_IS_LAYOUT(x) && _LV_COORD_PLAIN(x) == 100)
#define GET_FR(x) (_LV_COORD_PLAIN(x))
/********************** /**********************
* TYPEDEFS * TYPEDEFS
@@ -35,29 +29,59 @@ typedef struct {
lv_point_t grid_abs; lv_point_t grid_abs;
}item_repos_hint_t; }item_repos_hint_t;
typedef struct {
lv_coord_t * x;
lv_coord_t * y;
lv_coord_t * w;
lv_coord_t * h;
uint32_t col_num;
uint32_t row_num;
lv_coord_t grid_w;
lv_coord_t grid_h;
}_lv_grid_calc_t;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
**********************/ **********************/
void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, bool notify_parent);
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static void grid_update(lv_obj_t * cont); static void grid_update(lv_obj_t * cont);
static void full_refresh(lv_obj_t * cont);
static void calc(struct _lv_obj_t * obj, _lv_grid_calc_t * calc); static void calc(struct _lv_obj_t * obj, _lv_grid_calc_t * calc);
static void calc_free(_lv_grid_calc_t * calc); static void calc_free(_lv_grid_calc_t * calc);
static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c); static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c);
static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c); static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c);
static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t * hint); static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t * hint);
static lv_coord_t grid_place(lv_coord_t cont_size, bool auto_size, uint8_t place, lv_coord_t gap, uint32_t track_num, lv_coord_t * size_array, lv_coord_t * pos_array, bool reverse); static lv_coord_t grid_place(lv_coord_t cont_size, bool auto_size, uint8_t place, lv_coord_t gap, uint32_t track_num, lv_coord_t * size_array, lv_coord_t * pos_array, bool reverse);
static uint32_t count_tracks(const lv_coord_t * templ);
static inline const lv_coord_t * get_col_templ(lv_obj_t * obj) {return lv_obj_get_style_grid_column_template(obj, LV_PART_MAIN); }
static inline const lv_coord_t * get_row_templ(lv_obj_t * obj) {return lv_obj_get_style_grid_row_template(obj, LV_PART_MAIN); }
static inline uint8_t get_col_pos(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_column_pos(obj, LV_PART_MAIN); }
static inline uint8_t get_row_pos(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_row_pos(obj, LV_PART_MAIN); }
static inline uint8_t get_col_span(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_column_span(obj, LV_PART_MAIN); }
static inline uint8_t get_row_span(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_row_span(obj, LV_PART_MAIN); }
static inline uint8_t get_cell_col_place(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_x_place(obj, LV_PART_MAIN); }
static inline uint8_t get_cell_row_place(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_y_place(obj, LV_PART_MAIN); }
static inline uint8_t get_grid_col_place(lv_obj_t * obj) {return lv_obj_get_style_grid_column_place(obj, LV_PART_MAIN); }
static inline uint8_t get_grid_row_place(lv_obj_t * obj) {return lv_obj_get_style_grid_row_place(obj, LV_PART_MAIN); }
/********************** /**********************
* GLOBAL VARIABLES * GLOBAL VARIABLES
**********************/ **********************/
static const lv_coord_t grid_12_template[12] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), uint32_t LV_LAYOUT_GRID;
LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1)}; lv_style_prop_t LV_STYLE_GRID_COL_TEMPLATE;
const lv_grid_t grid_12 = {.base.update_cb = grid_update, .col_dsc = grid_12_template, .col_dsc_len = 12, .row_dsc = grid_12_template, .row_dsc_len = 12}; lv_style_prop_t LV_STYLE_GRID_COL_PLACE;
lv_style_prop_t LV_STYLE_GRID_ROW_TEMPLATE;
lv_style_prop_t LV_STYLE_GRID_ROW_PLACE;
lv_style_prop_t LV_STYLE_GRID_CELL_COL_POS;
lv_style_prop_t LV_STYLE_GRID_CELL_COL_SPAN;
lv_style_prop_t LV_STYLE_GRID_CELL_COL_PLACE;
lv_style_prop_t LV_STYLE_GRID_CELL_ROW_POS;
lv_style_prop_t LV_STYLE_GRID_CELL_ROW_SPAN;
lv_style_prop_t LV_STYLE_GRID_CELL_ROW_PLACE;
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@@ -66,50 +90,55 @@ const lv_grid_t grid_12 = {.base.update_cb = grid_update, .col_dsc = grid_12_tem
/********************** /**********************
* MACROS * MACROS
**********************/ **********************/
#define GET_CELL_POS(c) ((c) & CELL_POS_MASK)
#define GET_CELL_SPAN(c) (((c) & CELL_SPAN_MASK) >> CELL_SHIFT)
#define GET_CELL_PLACE(c) ((c) >> (CELL_SHIFT * 2) & 0x7)
/********************** /**********************
* GLOBAL FUNCTIONS * GLOBAL FUNCTIONS
**********************/ **********************/
void lv_grid_init(lv_grid_t * grid)
void lv_grid_init(void)
{ {
lv_memset_00(grid,sizeof(lv_grid_t)); LV_LAYOUT_GRID = lv_layout_register(grid_update);
grid->base.update_cb = grid_update;
grid->col_place = LV_GRID_START; LV_STYLE_GRID_COL_TEMPLATE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR;
grid->row_place = LV_GRID_START; LV_STYLE_GRID_ROW_TEMPLATE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR;
LV_STYLE_GRID_COL_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR;
LV_STYLE_GRID_ROW_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR;
LV_STYLE_GRID_CELL_ROW_SPAN = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR;
LV_STYLE_GRID_CELL_ROW_POS = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR;
LV_STYLE_GRID_CELL_COL_SPAN = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR;
LV_STYLE_GRID_CELL_COL_POS = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR;
LV_STYLE_GRID_CELL_COL_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR;
LV_STYLE_GRID_CELL_ROW_PLACE = lv_style_register_prop() | LV_STYLE_PROP_LAYOUT_REFR;
} }
void lv_grid_set_template(lv_grid_t * grid, const lv_coord_t * col_dsc, uint8_t col_cnt, const lv_coord_t * row_dsc, uint8_t row_cnt) void lv_obj_set_grid_template(lv_obj_t * obj, const lv_coord_t * col_templ, const lv_coord_t * row_templ)
{ {
grid->col_dsc = col_dsc; lv_obj_set_style_grid_column_template(obj, LV_PART_MAIN, LV_STATE_DEFAULT, col_templ);
grid->col_dsc_len = col_cnt; lv_obj_set_style_grid_row_template(obj, LV_PART_MAIN, LV_STATE_DEFAULT, row_templ);
grid->row_dsc = row_dsc; lv_obj_set_style_layout(obj, LV_PART_MAIN, LV_STATE_DEFAULT, LV_LAYOUT_GRID);
grid->row_dsc_len = row_cnt;
} }
void lv_obj_set_grid_place(lv_obj_t * obj, lv_grid_place_t hor_place, lv_grid_place_t ver_place)
void lv_grid_set_place(lv_grid_t * grid, uint8_t col_place, uint8_t row_place)
{ {
grid->col_place = col_place; lv_obj_set_style_grid_column_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, hor_place);
grid->row_place = row_place; lv_obj_set_style_grid_row_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, ver_place);
} }
void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_place_t hor_place, uint8_t col_pos, uint8_t col_span, void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_place_t hor_place, uint8_t col_pos, uint8_t col_span,
lv_grid_place_t ver_place, uint8_t row_pos, uint8_t row_span) lv_grid_place_t ver_place, uint8_t row_pos, uint8_t row_span)
{ {
if(!lv_obj_is_layout_positioned(obj)) return; lv_obj_set_style_grid_cell_column_pos(obj, LV_PART_MAIN, LV_STATE_DEFAULT, col_pos);
lv_obj_t * parent = lv_obj_get_parent(obj); lv_obj_set_style_grid_cell_row_pos(obj, LV_PART_MAIN, LV_STATE_DEFAULT, row_pos);
if(parent->spec_attr->layout_dsc->update_cb != grid_update) return; lv_obj_set_style_grid_cell_x_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, hor_place);
lv_obj_set_style_grid_cell_column_span(obj, LV_PART_MAIN, LV_STATE_DEFAULT, col_span);
obj->x_set = LV_COORD_SET_LAYOUT(col_pos | (col_span << CELL_SHIFT) | (hor_place << (CELL_SHIFT * 2))); lv_obj_set_style_grid_cell_row_span(obj, LV_PART_MAIN, LV_STATE_DEFAULT, row_span);
obj->y_set = LV_COORD_SET_LAYOUT(row_pos | (row_span << CELL_SHIFT) | (ver_place << (CELL_SHIFT * 2))); lv_obj_set_style_grid_cell_y_place(obj, LV_PART_MAIN, LV_STATE_DEFAULT, ver_place);
lv_obj_mark_layout_as_dirty(parent);
lv_obj_mark_layout_as_dirty(lv_obj_get_parent(obj));
} }
@@ -119,29 +148,15 @@ void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_place_t hor_place, uint8_t col
static void grid_update(lv_obj_t * cont) static void grid_update(lv_obj_t * cont)
{ {
if(cont->spec_attr == NULL) return;
if(cont->spec_attr->layout_dsc == NULL) return;
LV_LOG_INFO("update %p container", cont); LV_LOG_INFO("update %p container", cont);
full_refresh(cont); const lv_coord_t * col_templ = get_col_templ(cont);
const lv_coord_t * row_templ = get_row_templ(cont);
if(col_templ == NULL || row_templ == NULL) return;
LV_TRACE_LAYOUT("finished");
}
/**
* Refresh the all grid item on a container
* @param cont pointer to a grid container object
*/
static void full_refresh(lv_obj_t * cont)
{
const lv_grid_t * g = (const lv_grid_t *)cont->spec_attr->layout_dsc;
/*Calculate the grid*/
if(g == NULL) return;
_lv_grid_calc_t c; _lv_grid_calc_t c;
calc(cont, &c); calc(cont, &c);
item_repos_hint_t hint; item_repos_hint_t hint;
lv_memset_00(&hint, sizeof(hint)); lv_memset_00(&hint, sizeof(hint));
@@ -155,15 +170,17 @@ static void full_refresh(lv_obj_t * cont)
uint32_t i; uint32_t i;
for(i = 0; i < cont->spec_attr->child_cnt; i++) { for(i = 0; i < cont->spec_attr->child_cnt; i++) {
lv_obj_t * item = cont->spec_attr->children[i]; lv_obj_t * item = cont->spec_attr->children[i];
if(LV_COORD_IS_LAYOUT(item->x_set) && LV_COORD_IS_LAYOUT(item->y_set)) { item_repos(item, &c, &hint);
item_repos(item, &c, &hint);
}
} }
calc_free(&c); calc_free(&c);
if(cont->w_set == LV_SIZE_CONTENT || cont->h_set == LV_SIZE_CONTENT) { lv_coord_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN);
lv_obj_set_size(cont, cont->w_set, cont->h_set); lv_coord_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN);
if(w_set == LV_SIZE_CONTENT || h_set == LV_SIZE_CONTENT) {
lv_obj_refr_size(cont);
} }
LV_TRACE_LAYOUT("finished");
} }
/** /**
@@ -174,10 +191,6 @@ static void full_refresh(lv_obj_t * cont)
*/ */
static void calc(struct _lv_obj_t * cont, _lv_grid_calc_t * calc_out) static void calc(struct _lv_obj_t * cont, _lv_grid_calc_t * calc_out)
{ {
const lv_grid_t * g = (const lv_grid_t *)cont->spec_attr->layout_dsc;
if(g->col_dsc == NULL || g->row_dsc == NULL) return;
if(g->col_dsc_len == 0 || g->row_dsc_len == 0) return;
if(lv_obj_get_child(cont, 0) == NULL) { if(lv_obj_get_child(cont, 0) == NULL) {
lv_memset_00(calc_out, sizeof(_lv_grid_calc_t)); lv_memset_00(calc_out, sizeof(_lv_grid_calc_t));
return; return;
@@ -190,13 +203,16 @@ static void calc(struct _lv_obj_t * cont, _lv_grid_calc_t * calc_out)
lv_coord_t row_gap = lv_obj_get_style_pad_row(cont, LV_PART_MAIN); lv_coord_t row_gap = lv_obj_get_style_pad_row(cont, LV_PART_MAIN);
bool rev = lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL ? true : false; bool rev = lv_obj_get_base_dir(cont) == LV_BIDI_DIR_RTL ? true : false;
bool auto_w = cont->w_set == LV_SIZE_CONTENT ? true : false;
lv_coord_t cont_w = lv_obj_get_width_fit(cont);
calc_out->grid_w = grid_place(cont_w, auto_w, g->col_place, col_gap, calc_out->col_num, calc_out->w, calc_out->x, rev);
bool auto_h = cont->h_set == LV_SIZE_CONTENT ? true : false; lv_coord_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN);
lv_coord_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN);
bool auto_w = w_set == LV_SIZE_CONTENT ? true : false;
lv_coord_t cont_w = lv_obj_get_width_fit(cont);
calc_out->grid_w = grid_place(cont_w, auto_w, get_grid_col_place(cont), col_gap, calc_out->col_num, calc_out->w, calc_out->x, rev);
bool auto_h = h_set == LV_SIZE_CONTENT ? true : false;
lv_coord_t cont_h = lv_obj_get_height_fit(cont); lv_coord_t cont_h = lv_obj_get_height_fit(cont);
calc_out->grid_h = grid_place(cont_h, auto_h, g->row_place, row_gap, calc_out->row_num, calc_out->h, calc_out->y, false); calc_out->grid_h = grid_place(cont_h, auto_h, get_grid_row_place(cont), row_gap, calc_out->row_num, calc_out->h, calc_out->y, false);
LV_ASSERT_MEM_INTEGRITY(); LV_ASSERT_MEM_INTEGRITY();
} }
@@ -215,30 +231,29 @@ static void calc_free(_lv_grid_calc_t * calc)
static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c) static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c)
{ {
const lv_grid_t * grid = (const lv_grid_t *)cont->spec_attr->layout_dsc; const lv_coord_t * col_templ = get_col_templ(cont);
uint32_t i;
lv_coord_t cont_w = lv_obj_get_width_fit(cont); lv_coord_t cont_w = lv_obj_get_width_fit(cont);
c->col_num = grid->col_dsc_len; c->col_num = count_tracks(col_templ);
c->x = lv_mem_buf_get(sizeof(lv_coord_t) * c->col_num); c->x = lv_mem_buf_get(sizeof(lv_coord_t) * c->col_num);
c->w = lv_mem_buf_get(sizeof(lv_coord_t) * c->col_num); c->w = lv_mem_buf_get(sizeof(lv_coord_t) * c->col_num);
/*Set sizes for CONTENT cells*/ /*Set sizes for CONTENT cells*/
uint32_t i;
for(i = 0; i < c->col_num; i++) { for(i = 0; i < c->col_num; i++) {
lv_coord_t size = LV_COORD_MIN; lv_coord_t size = LV_COORD_MIN;
if(IS_CONTENT(grid->col_dsc[i])) { if(IS_CONTENT(col_templ[i])) {
/*Check the size of children of this cell*/ /*Check the size of children of this cell*/
uint32_t ci; uint32_t ci;
for(ci = 0; ci < lv_obj_get_child_cnt(cont); ci++) { for(ci = 0; ci < lv_obj_get_child_cnt(cont); ci++) {
lv_obj_t * item = lv_obj_get_child(cont, ci); lv_obj_t * item = lv_obj_get_child(cont, ci);
if(LV_COORD_IS_LAYOUT(item->x_set) == false || LV_COORD_IS_LAYOUT(item->y_set) == false) continue;
if(lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) continue; if(lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) continue;
uint32_t col_pos = GET_CELL_POS(item->x_set); uint32_t col_span = get_col_span(item);
if(col_pos != i) continue;
uint32_t col_span = GET_CELL_SPAN(item->x_set);
if(col_span != 1) continue; if(col_span != 1) continue;
uint32_t col_pos = get_col_pos(item);
if(col_pos != i) continue;
size = LV_MAX(size, lv_obj_get_width(item)); size = LV_MAX(size, lv_obj_get_width(item));
} }
if(size >= 0) c->w[i] = size; if(size >= 0) c->w[i] = size;
@@ -250,7 +265,7 @@ static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c)
lv_coord_t grid_w = 0; lv_coord_t grid_w = 0;
for(i = 0; i < c->col_num; i++) { for(i = 0; i < c->col_num; i++) {
lv_coord_t x = grid->col_dsc[i]; lv_coord_t x = col_templ[i];
if(IS_FR(x)) { if(IS_FR(x)) {
col_fr_cnt += GET_FR(x); col_fr_cnt += GET_FR(x);
} }
@@ -268,7 +283,7 @@ static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c)
lv_coord_t free_w = cont_w - grid_w; lv_coord_t free_w = cont_w - grid_w;
for(i = 0; i < c->col_num; i++) { for(i = 0; i < c->col_num; i++) {
lv_coord_t x = grid->col_dsc[i]; lv_coord_t x = col_templ[i];
if(IS_FR(x)) { if(IS_FR(x)) {
lv_coord_t f = GET_FR(x); lv_coord_t f = GET_FR(x);
c->w[i] = (free_w * f) / col_fr_cnt; c->w[i] = (free_w * f) / col_fr_cnt;
@@ -278,27 +293,26 @@ static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c)
static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c) static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c)
{ {
const lv_grid_t * grid = (const lv_grid_t *)cont->spec_attr->layout_dsc;
uint32_t i; uint32_t i;
const lv_coord_t * row_templ = get_row_templ(cont);
c->row_num = grid->row_dsc_len; c->row_num = count_tracks(row_templ);
c->y = lv_mem_buf_get(sizeof(lv_coord_t) * c->row_num); c->y = lv_mem_buf_get(sizeof(lv_coord_t) * c->row_num);
c->h = lv_mem_buf_get(sizeof(lv_coord_t) * c->row_num); c->h = lv_mem_buf_get(sizeof(lv_coord_t) * c->row_num);
/*Set sizes for CONTENT cells*/ /*Set sizes for CONTENT cells*/
for(i = 0; i < c->row_num; i++) { for(i = 0; i < c->row_num; i++) {
lv_coord_t size = LV_COORD_MIN; lv_coord_t size = LV_COORD_MIN;
if(IS_CONTENT(grid->row_dsc[i])) { if(IS_CONTENT(row_templ[i])) {
/*Check the size of children of this cell*/ /*Check the size of children of this cell*/
uint32_t ci; uint32_t ci;
for(ci = 0; ci < lv_obj_get_child_cnt(cont); ci++) { for(ci = 0; ci < lv_obj_get_child_cnt(cont); ci++) {
lv_obj_t * item = lv_obj_get_child(cont, ci); lv_obj_t * item = lv_obj_get_child(cont, ci);
if(LV_COORD_IS_LAYOUT(item->x_set) == false || LV_COORD_IS_LAYOUT(item->y_set) == false) continue;
if(lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) continue; if(lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) continue;
uint32_t row_pos = GET_CELL_POS(item->y_set); uint32_t row_span = get_row_span(item);
if(row_pos != i) continue;
uint32_t row_span = GET_CELL_SPAN(item->y_set);
if(row_span != 1) continue; if(row_span != 1) continue;
uint32_t row_pos = get_row_pos(item);
if(row_pos != i) continue;
size = LV_MAX(size, lv_obj_get_height(item)); size = LV_MAX(size, lv_obj_get_height(item));
} }
if(size >= 0) c->h[i] = size; if(size >= 0) c->h[i] = size;
@@ -310,7 +324,7 @@ static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c)
lv_coord_t grid_h = 0; lv_coord_t grid_h = 0;
for(i = 0; i < c->row_num; i++) { for(i = 0; i < c->row_num; i++) {
lv_coord_t x = grid->row_dsc[i]; lv_coord_t x = row_templ[i];
if(IS_FR(x)) { if(IS_FR(x)) {
row_fr_cnt += GET_FR(x); row_fr_cnt += GET_FR(x);
} else if (IS_CONTENT(x)) { } else if (IS_CONTENT(x)) {
@@ -322,11 +336,11 @@ static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c)
} }
lv_coord_t row_gap = lv_obj_get_style_pad_row(cont, LV_PART_MAIN); lv_coord_t row_gap = lv_obj_get_style_pad_row(cont, LV_PART_MAIN);
lv_coord_t cont_h = lv_obj_get_height_fit(cont) - row_gap * (grid->row_dsc_len - 1); lv_coord_t cont_h = lv_obj_get_height_fit(cont) - row_gap * (c->row_num - 1);
lv_coord_t free_h = cont_h - grid_h; lv_coord_t free_h = cont_h - grid_h;
for(i = 0; i < grid->row_dsc_len; i++) { for(i = 0; i < c->row_num; i++) {
lv_coord_t x = grid->row_dsc[i]; lv_coord_t x = row_templ[i];
if(IS_FR(x)) { if(IS_FR(x)) {
lv_coord_t f = GET_FR(x); lv_coord_t f = GET_FR(x);
c->h[i] = (free_h * f) / row_fr_cnt; c->h[i] = (free_h * f) / row_fr_cnt;
@@ -343,14 +357,16 @@ static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c)
*/ */
static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t * hint) static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t * hint)
{ {
if(LV_COORD_IS_LAYOUT(item->x_set) == 0 || LV_COORD_IS_LAYOUT(item->y_set) == 0) return;
if(lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) return; if(lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) return;
uint32_t col_span = GET_CELL_SPAN(item->x_set); uint32_t col_span = get_col_span(item);
uint32_t row_span = GET_CELL_SPAN(item->y_set); uint32_t row_span = get_row_span(item);
if(row_span == 0 || col_span == 0) return; if(row_span == 0 || col_span == 0) return;
uint32_t col_pos = GET_CELL_POS(item->x_set); uint32_t col_pos = get_col_pos(item);
uint32_t row_pos = GET_CELL_POS(item->y_set); uint32_t row_pos = get_row_pos(item);
lv_grid_place_t col_place = get_cell_col_place(item);
lv_grid_place_t row_place = get_cell_row_place(item);
lv_coord_t col_x1 = c->x[col_pos]; lv_coord_t col_x1 = c->x[col_pos];
lv_coord_t col_x2 = c->x[col_pos + col_span - 1] + c->w[col_pos + col_span - 1]; lv_coord_t col_x2 = c->x[col_pos + col_span - 1] + c->w[col_pos + col_span - 1];
@@ -360,13 +376,11 @@ static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t *
lv_coord_t row_y2 = c->y[row_pos + row_span - 1] + c->h[row_pos + row_span - 1]; lv_coord_t row_y2 = c->y[row_pos + row_span - 1] + c->h[row_pos + row_span - 1];
lv_coord_t row_h = row_y2 - row_y1; lv_coord_t row_h = row_y2 - row_y1;
uint8_t x_flag = GET_CELL_PLACE(item->x_set);
uint8_t y_flag = GET_CELL_PLACE(item->y_set);
/*If the item has RTL base dir switch start and end*/ /*If the item has RTL base dir switch start and end*/
if(lv_obj_get_base_dir(item) == LV_BIDI_DIR_RTL) { if(lv_obj_get_base_dir(item) == LV_BIDI_DIR_RTL) {
if(x_flag == LV_GRID_START) x_flag = LV_GRID_END; if(col_place == LV_GRID_START) col_place = LV_GRID_END;
else if(x_flag == LV_GRID_END) x_flag = LV_GRID_START; else if(col_place == LV_GRID_END) col_place = LV_GRID_START;
} }
lv_coord_t x; lv_coord_t x;
@@ -374,42 +388,45 @@ static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t *
lv_coord_t item_w = lv_area_get_width(&item->coords); lv_coord_t item_w = lv_area_get_width(&item->coords);
lv_coord_t item_h = lv_area_get_height(&item->coords); lv_coord_t item_h = lv_area_get_height(&item->coords);
if(item->w_set == LV_SIZE_LAYOUT) item->w_set = item_w; switch(col_place) {
if(item->h_set == LV_SIZE_LAYOUT) item->h_set = item_h;
switch(x_flag) {
default: default:
case LV_GRID_START: case LV_GRID_START:
x = c->x[col_pos]; x = c->x[col_pos];
item->w_layout = 0;
break; break;
case LV_GRID_STRETCH: case LV_GRID_STRETCH:
x = c->x[col_pos]; x = c->x[col_pos];
item_w = col_w; item_w = col_w;
item->w_set = LV_SIZE_LAYOUT; item->w_layout = 1;
break; break;
case LV_GRID_CENTER: case LV_GRID_CENTER:
x = c->x[col_pos] + (col_w - item_w) / 2; x = c->x[col_pos] + (col_w - item_w) / 2;
item->w_layout = 0;
break; break;
case LV_GRID_END: case LV_GRID_END:
x = c->x[col_pos] + col_w - lv_obj_get_width(item); x = c->x[col_pos] + col_w - lv_obj_get_width(item);
item->w_layout = 0;
break; break;
} }
switch(y_flag) { switch(row_place) {
default: default:
case LV_GRID_START: case LV_GRID_START:
y = c->y[row_pos]; y = c->y[row_pos];
item->h_layout = 0;
break; break;
case LV_GRID_STRETCH: case LV_GRID_STRETCH:
y = c->y[row_pos]; y = c->y[row_pos];
item_h = row_h; item_h = row_h;
item->h_set = LV_SIZE_LAYOUT; item->h_layout = 1;
break; break;
case LV_GRID_CENTER: case LV_GRID_CENTER:
y = c->y[row_pos] + (row_h - item_h) / 2; y = c->y[row_pos] + (row_h - item_h) / 2;
item->h_layout = 0;
break; break;
case LV_GRID_END: case LV_GRID_END:
y = c->y[row_pos] + row_h - lv_obj_get_height(item); y = c->y[row_pos] + row_h - lv_obj_get_height(item);
item->h_layout = 0;
break; break;
} }
@@ -421,15 +438,21 @@ static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t *
lv_area_set_width(&item->coords, item_w); lv_area_set_width(&item->coords, item_w);
lv_area_set_height(&item->coords, item_h); lv_area_set_height(&item->coords, item_h);
lv_obj_invalidate(item); lv_obj_invalidate(item);
lv_event_send(item, LV_EVENT_COORD_CHANGED, &old_coords); lv_event_send(item, LV_EVENT_SIZE_CHANGED, &old_coords);
lv_event_send(lv_obj_get_parent(item), LV_EVENT_CHILD_CHANGED, item);
} }
bool moved = true; lv_coord_t diff_x = hint->grid_abs.x + x - item->coords.x1;
if(hint) { lv_coord_t diff_y = hint->grid_abs.y + y - item->coords.y1;
if(hint->grid_abs.x + x == item->coords.x1 && hint->grid_abs.y + y == item->coords.y1) moved = false; if(diff_x || diff_y) {
lv_obj_invalidate(item);
item->coords.x1 += diff_x;
item->coords.x2 += diff_x;
item->coords.y1 += diff_y;
item->coords.y2 += diff_y;
lv_obj_invalidate(item);
lv_obj_move_children_by(item, diff_x, diff_y, true);
} }
if(moved) lv_obj_move_to(item, x, y, false);
} }
/** /**
@@ -509,4 +532,13 @@ static lv_coord_t grid_place(lv_coord_t cont_size, bool auto_size, uint8_t plac
return total_gird_size; return total_gird_size;
} }
static uint32_t count_tracks(const lv_coord_t * templ)
{
uint32_t i;
for(i = 0; templ[i] != LV_COORD_MAX; i++);
return i;
}
#endif /*LV_USE_GRID*/ #endif /*LV_USE_GRID*/

View File

@@ -14,11 +14,19 @@ extern "C" {
* INCLUDES * INCLUDES
*********************/ *********************/
#include "../../../core/lv_obj.h" #include "../../../core/lv_obj.h"
#if LV_USE_GRID
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
#if LV_USE_GRID /**
* Can be used track size to make the track fill the free space.
* @param x how much space to take proportionally to other FR tracks
* @return a special track size
*/
#define LV_GRID_FR(x) (LV_COORD_MAX - 100 + x)
#define LV_GRID_CONTENT (LV_COORD_MAX - 101)
#define LV_GRID_TEMPLATE_LAST (LV_COORD_MAX)
/********************** /**********************
* TYPEDEFS * TYPEDEFS
@@ -37,56 +45,29 @@ typedef enum {
LV_GRID_SPACE_BETWEEN, LV_GRID_SPACE_BETWEEN,
}lv_grid_place_t; }lv_grid_place_t;
typedef struct { /**********************
lv_layout_dsc_t base; /*The first element must be the update callback*/ * GLOBAL VARIABLES
const lv_coord_t * col_dsc; **********************/
const lv_coord_t * row_dsc;
uint8_t col_dsc_len;
uint8_t row_dsc_len;
uint8_t col_place;
uint8_t row_place;
}lv_grid_t;
typedef struct { extern uint32_t LV_LAYOUT_GRID;
lv_coord_t * x; extern lv_style_prop_t LV_STYLE_GRID_COL_TEMPLATE;
lv_coord_t * y; extern lv_style_prop_t LV_STYLE_GRID_COL_PLACE;
lv_coord_t * w; extern lv_style_prop_t LV_STYLE_GRID_ROW_TEMPLATE;
lv_coord_t * h; extern lv_style_prop_t LV_STYLE_GRID_ROW_PLACE;
uint32_t col_num; extern lv_style_prop_t LV_STYLE_GRID_CELL_COL_POS;
uint32_t row_num; extern lv_style_prop_t LV_STYLE_GRID_CELL_COL_SPAN;
lv_coord_t grid_w; extern lv_style_prop_t LV_STYLE_GRID_CELL_COL_PLACE;
lv_coord_t grid_h; extern lv_style_prop_t LV_STYLE_GRID_CELL_ROW_POS;
}_lv_grid_calc_t; extern lv_style_prop_t LV_STYLE_GRID_CELL_ROW_SPAN;
extern lv_style_prop_t LV_STYLE_GRID_CELL_ROW_PLACE;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
**********************/ **********************/
void lv_obj_set_grid_template(lv_obj_t * obj, const lv_coord_t * col_templ, const lv_coord_t * row_templ);
/** void lv_obj_set_grid_place(lv_obj_t * obj, lv_grid_place_t hor_place, lv_grid_place_t ver_place);
* Initialize a grid layout the default values
* @param grid pointer to a grid layout descriptor
*/
void lv_grid_init(lv_grid_t * grid);
/**
* Set the number of rows and columns and their sizes
* @param grid pointer to a grid layout descriptor
* @param col_dsc an array with the column widths
* @param col_cnt number of columns (max 16)
* @param row_dsc an array with the row heights
* @param row_cnt number of rows (max 16)
* @note `LV_GRID_FR(x)` can be used as track size.
*/
void lv_grid_set_template(lv_grid_t * grid, const lv_coord_t * col_dsc, uint8_t col_cnt, const lv_coord_t * row_dsc, uint8_t row_cnt);
/**
* Set how to place (where to align) the rows and columns
* @param grid
* @param col_place
* @param row_place
*/
void lv_grid_set_place(lv_grid_t * grid, uint8_t col_place, uint8_t row_place);
/** /**
* Set the cell of an object. The object's parent needs to have grid layout, else nothing will happen * Set the cell of an object. The object's parent needs to have grid layout, else nothing will happen
@@ -101,15 +82,6 @@ void lv_grid_set_place(lv_grid_t * grid, uint8_t col_place, uint8_t row_place);
void lv_obj_set_grid_cell(struct _lv_obj_t * obj, lv_grid_place_t hor_place, uint8_t col_pos, uint8_t col_span, void lv_obj_set_grid_cell(struct _lv_obj_t * obj, lv_grid_place_t hor_place, uint8_t col_pos, uint8_t col_span,
lv_grid_place_t ver_place, uint8_t row_pos, uint8_t row_span); lv_grid_place_t ver_place, uint8_t row_pos, uint8_t row_span);
/**
* Can be used track size to make the track fill the free space.
* @param x how much space to take proportionally to other FR tracks
* @return a special track size
*/
#define LV_GRID_FR(x) (LV_COORD_SET_LAYOUT(x))
#define LV_GRID_CONTENT (LV_COORD_SET_LAYOUT(100))
/** /**
* Just a wrapper to `LV_GRID_FR` for bindings. * Just a wrapper to `LV_GRID_FR` for bindings.
*/ */
@@ -118,10 +90,236 @@ static inline lv_coord_t lv_grid_fr(uint8_t x)
return LV_GRID_FR(x); return LV_GRID_FR(x);
} }
static inline void lv_style_set_grid_row_template(lv_style_t * style, const lv_coord_t * value)
{
lv_style_value_t v = {
.ptr = (const void *)value
};
lv_style_set_prop(style, LV_STYLE_GRID_ROW_TEMPLATE, v);
}
static inline void lv_style_set_grid_column_template(lv_style_t * style, const lv_coord_t * value)
{
lv_style_value_t v = {
.ptr = (const void *)value
};
lv_style_set_prop(style, LV_STYLE_GRID_COL_TEMPLATE, v);
}
static inline void lv_style_set_grid_row_place(lv_style_t * style, lv_grid_place_t value)
{
lv_style_value_t v = {
.num = (lv_grid_place_t)value
};
lv_style_set_prop(style, LV_STYLE_GRID_ROW_PLACE, v);
}
static inline void lv_style_set_grid_col_place(lv_style_t * style, lv_grid_place_t value)
{
lv_style_value_t v = {
.num = (lv_grid_place_t)value
};
lv_style_set_prop(style, LV_STYLE_GRID_COL_PLACE, v);
}
static inline void lv_style_set_grid_cell_column_pos(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
.num = value
};
lv_style_set_prop(style, LV_STYLE_GRID_CELL_COL_POS, v);
}
static inline void lv_style_set_grid_cell_column_span(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
.num = value
};
lv_style_set_prop(style, LV_STYLE_GRID_CELL_COL_SPAN, v);
}
static inline void lv_style_set_grid_cell_row_pos(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
.num = value
};
lv_style_set_prop(style, LV_STYLE_GRID_CELL_ROW_POS, v);
}
static inline void lv_style_set_grid_cell_row_span(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
.num = value
};
lv_style_set_prop(style, LV_STYLE_GRID_CELL_ROW_SPAN, v);
}
static inline void lv_style_set_grid_cell_x_place(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
.num = value
};
lv_style_set_prop(style, LV_STYLE_GRID_CELL_COL_PLACE, v);
}
static inline void lv_style_set_grid_cell_y_place(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
.num = value
};
lv_style_set_prop(style, LV_STYLE_GRID_CELL_ROW_PLACE, v);
}
static inline void lv_obj_set_style_grid_row_template(lv_obj_t * obj, lv_part_t part, lv_state_t state, const lv_coord_t * value)
{
lv_style_value_t v = {
.ptr = (const void *)value
};
lv_obj_set_local_style_prop(obj, part, state,LV_STYLE_GRID_ROW_TEMPLATE, v);
}
static inline void lv_obj_set_style_grid_column_template(lv_obj_t * obj, lv_part_t part, lv_state_t state, const lv_coord_t * value)
{
lv_style_value_t v = {
.ptr = (const void *)value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_GRID_COL_TEMPLATE, v);
}
static inline void lv_obj_set_style_grid_row_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_grid_place_t value)
{
lv_style_value_t v = {
.num = (int32_t) value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_GRID_ROW_PLACE, v);
}
static inline void lv_obj_set_style_grid_column_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_grid_place_t value)
{
lv_style_value_t v = {
.num = (int32_t) value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_GRID_COL_PLACE, v);
}
static inline void lv_obj_set_style_grid_cell_column_pos(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_coord_t value)
{
lv_style_value_t v = {
.num = value
};
lv_obj_set_local_style_prop(obj, part, state,LV_STYLE_GRID_CELL_COL_POS, v);
}
static inline void lv_obj_set_style_grid_cell_column_span(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_coord_t value)
{
lv_style_value_t v = {
.num = value
};
lv_obj_set_local_style_prop(obj, part, state,LV_STYLE_GRID_CELL_COL_SPAN, v);
}
static inline void lv_obj_set_style_grid_cell_row_pos(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_coord_t value)
{
lv_style_value_t v = {
.num = value
};
lv_obj_set_local_style_prop(obj, part, state,LV_STYLE_GRID_CELL_ROW_POS, v);
}
static inline void lv_obj_set_style_grid_cell_row_span(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_coord_t value)
{
lv_style_value_t v = {
.num = value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_GRID_CELL_ROW_SPAN, v);
}
static inline void lv_obj_set_style_grid_cell_x_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_coord_t value)
{
lv_style_value_t v = {
.num = value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_GRID_CELL_COL_PLACE, v);
}
static inline void lv_obj_set_style_grid_cell_y_place(lv_obj_t * obj, lv_part_t part, lv_state_t state, lv_coord_t value)
{
lv_style_value_t v = {
.num = value
};
lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_GRID_CELL_ROW_PLACE, v);
}
static inline const lv_coord_t * lv_obj_get_style_grid_row_template(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_ROW_TEMPLATE);
return (const lv_coord_t *)v.ptr;
}
static inline const lv_coord_t * lv_obj_get_style_grid_column_template(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_COL_TEMPLATE);
return (const lv_coord_t *)v.ptr;
}
static inline lv_grid_place_t lv_obj_get_style_grid_row_place(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_ROW_PLACE);
return (lv_grid_place_t)v.num;
}
static inline lv_grid_place_t lv_obj_get_style_grid_column_place(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_COL_PLACE);
return (lv_grid_place_t)v.num;
}
static inline lv_coord_t lv_obj_get_style_grid_cell_column_pos(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_COL_POS);
return (lv_coord_t)v.num;
}
static inline lv_coord_t lv_obj_get_style_grid_cell_column_span(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_COL_SPAN);
return (lv_coord_t)v.num;
}
static inline lv_coord_t lv_obj_get_style_grid_cell_row_pos(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_ROW_POS);
return (lv_coord_t)v.num;
}
static inline lv_coord_t lv_obj_get_style_grid_cell_row_span(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_ROW_SPAN);
return (lv_coord_t)v.num;
}
static inline lv_coord_t lv_obj_get_style_grid_cell_x_place(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_COL_PLACE);
return (lv_coord_t)v.num;
}
static inline lv_coord_t lv_obj_get_style_grid_cell_y_place(const struct _lv_obj_t * obj, uint32_t part)
{
lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_ROW_PLACE);
return (lv_coord_t)v.num;
}
/********************** /**********************
* GLOBAL VARIABLES * GLOBAL VARIABLES
**********************/ **********************/
extern const lv_grid_t grid_12;
/********************** /**********************
* MACROS * MACROS

View File

@@ -97,6 +97,9 @@ static void style_init(void)
lv_style_set_line_color(&styles->light, COLOR_MID); lv_style_set_line_color(&styles->light, COLOR_MID);
lv_style_set_arc_width(&styles->light, LV_DPX(2)); lv_style_set_arc_width(&styles->light, LV_DPX(2));
lv_style_set_arc_color(&styles->light, COLOR_MID); lv_style_set_arc_color(&styles->light, COLOR_MID);
lv_style_set_width(&styles->light, 100);
lv_style_set_height(&styles->light, 60);
style_init_reset(&styles->dark); style_init_reset(&styles->dark);
lv_style_set_bg_opa(&styles->dark, LV_OPA_COVER); lv_style_set_bg_opa(&styles->dark, LV_OPA_COVER);
@@ -109,6 +112,8 @@ static void style_init(void)
lv_style_set_line_color(&styles->dark, COLOR_DIM); lv_style_set_line_color(&styles->dark, COLOR_DIM);
lv_style_set_arc_width(&styles->dark, LV_DPX(2)); lv_style_set_arc_width(&styles->dark, LV_DPX(2));
lv_style_set_arc_color(&styles->dark, COLOR_DIM); lv_style_set_arc_color(&styles->dark, COLOR_DIM);
lv_style_set_width(&styles->dark, 100);
lv_style_set_height(&styles->dark, 60);
static lv_color_filter_dsc_t dark_filter; static lv_color_filter_dsc_t dark_filter;
lv_color_filter_dsc_init(&dark_filter, dark_color_filter_cb); lv_color_filter_dsc_init(&dark_filter, dark_color_filter_cb);

View File

@@ -179,7 +179,7 @@ static lv_color_t dark_color_filter_cb(const lv_color_filter_dsc_t * f, lv_color
static lv_color_t grey_filter_cb(const lv_color_filter_dsc_t * f, lv_color_t color, lv_opa_t opa) static lv_color_t grey_filter_cb(const lv_color_filter_dsc_t * f, lv_color_t color, lv_opa_t opa)
{ {
LV_UNUSED(f); LV_UNUSED(f);
return lv_color_mix(lv_color_white(), color, opa); return lv_color_mix(lv_color_grey_lighten_2(), color, opa);
} }
static void style_init(void) static void style_init(void)
@@ -230,8 +230,8 @@ static void style_init(void)
lv_style_set_bg_opa(&styles->scr, LV_OPA_COVER); lv_style_set_bg_opa(&styles->scr, LV_OPA_COVER);
lv_style_set_bg_color(&styles->scr, COLOR_SCR); lv_style_set_bg_color(&styles->scr, COLOR_SCR);
lv_style_set_text_color(&styles->scr, COLOR_SCR_TEXT); lv_style_set_text_color(&styles->scr, COLOR_SCR_TEXT);
lv_style_set_pad_row(&styles->scr, PAD_SMALL * disp_size); lv_style_set_pad_row(&styles->scr, PAD_SMALL);
lv_style_set_pad_column(&styles->scr, PAD_SMALL * disp_size); lv_style_set_pad_column(&styles->scr, PAD_SMALL);
style_init_reset(&styles->card); style_init_reset(&styles->card);
lv_style_set_radius(&styles->card, RADIUS_DEFAULT); lv_style_set_radius(&styles->card, RADIUS_DEFAULT);
@@ -269,6 +269,13 @@ static void style_init(void)
lv_style_set_pad_ver(&styles->btn, PAD_SMALL); lv_style_set_pad_ver(&styles->btn, PAD_SMALL);
lv_style_set_pad_column(&styles->btn, LV_DPX(5)); lv_style_set_pad_column(&styles->btn, LV_DPX(5));
lv_style_set_pad_row(&styles->btn, LV_DPX(5)); lv_style_set_pad_row(&styles->btn, LV_DPX(5));
#if LV_USE_FLEX
lv_style_set_layout(&styles->btn, LV_LAYOUT_FLEX);
lv_style_set_flex_flow(&styles->btn, LV_FLEX_FLOW_ROW);
lv_style_set_flex_main_place(&styles->btn, LV_FLEX_PLACE_CENTER);
lv_style_set_flex_cross_place(&styles->btn, LV_FLEX_PLACE_CENTER);
lv_style_set_flex_track_place(&styles->btn, LV_FLEX_PLACE_CENTER);
#endif
static lv_color_filter_dsc_t dark_filter; static lv_color_filter_dsc_t dark_filter;
@@ -283,7 +290,7 @@ static void style_init(void)
style_init_reset(&styles->disabled); style_init_reset(&styles->disabled);
lv_style_set_color_filter_dsc(&styles->disabled, &grey_filter); lv_style_set_color_filter_dsc(&styles->disabled, &grey_filter);
lv_style_set_color_filter_opa(&styles->disabled, LV_OPA_70); lv_style_set_color_filter_opa(&styles->disabled, LV_OPA_50);
style_init_reset(&styles->clip_corner); style_init_reset(&styles->clip_corner);
lv_style_set_clip_corner(&styles->clip_corner, true); lv_style_set_clip_corner(&styles->clip_corner, true);
@@ -501,6 +508,8 @@ static void style_init(void)
lv_style_set_border_side(&styles->list_btn, LV_BORDER_SIDE_BOTTOM); lv_style_set_border_side(&styles->list_btn, LV_BORDER_SIDE_BOTTOM);
lv_style_set_pad_all(&styles->list_btn, PAD_SMALL); lv_style_set_pad_all(&styles->list_btn, PAD_SMALL);
lv_style_set_pad_column(&styles->list_btn, PAD_SMALL); lv_style_set_pad_column(&styles->list_btn, PAD_SMALL);
lv_style_set_flex_flow(&styles->list_btn, LV_FLEX_FLOW_ROW);
lv_style_set_layout(&styles->list_btn, LV_LAYOUT_FLEX);
style_init_reset(&styles->list_item_grow); style_init_reset(&styles->list_item_grow);
lv_style_set_transform_width(&styles->list_item_grow, PAD_DEF); lv_style_set_transform_width(&styles->list_item_grow, PAD_DEF);

View File

@@ -221,7 +221,7 @@ static void my_constructor(lv_obj_t * obj, const lv_obj_t * copy)
calendar->highlighted_dates = NULL; calendar->highlighted_dates = NULL;
calendar->highlighted_dates_num = 0; calendar->highlighted_dates_num = 0;
lv_obj_set_size(obj, LV_DPX(240), LV_DPX(240)); lv_obj_set_size(obj, LV_DPX(180), LV_DPX(180));
lv_memset_00(calendar->nums, sizeof(calendar->nums)); lv_memset_00(calendar->nums, sizeof(calendar->nums));
uint8_t i; uint8_t i;

View File

@@ -56,7 +56,8 @@ lv_obj_t * lv_calendar_header_arrow_create(lv_obj_t * parent, lv_obj_t * calenda
lv_coord_t w = lv_obj_get_width(calendar); lv_coord_t w = lv_obj_get_width(calendar);
lv_obj_set_size(header, w, LV_SIZE_CONTENT); lv_obj_set_size(header, w, LV_SIZE_CONTENT);
lv_obj_set_layout(header, &lv_flex_row_center); lv_obj_set_flex_flow(header, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_place(header, LV_FLEX_PLACE_START, LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_START);
lv_obj_t * mo_prev = lv_btn_create(header, NULL); lv_obj_t * mo_prev = lv_btn_create(header, NULL);
lv_obj_set_style_content_text(mo_prev, LV_PART_MAIN, LV_STATE_DEFAULT, LV_SYMBOL_LEFT); lv_obj_set_style_content_text(mo_prev, LV_PART_MAIN, LV_STATE_DEFAULT, LV_SYMBOL_LEFT);

View File

@@ -65,21 +65,20 @@ lv_obj_t * lv_calendar_header_dropdown_create(lv_obj_t * parent, lv_obj_t * cale
lv_coord_t w = lv_obj_get_width(calendar); lv_coord_t w = lv_obj_get_width(calendar);
lv_obj_set_size(header, w, LV_SIZE_CONTENT); lv_obj_set_size(header, w, LV_SIZE_CONTENT);
lv_obj_set_layout(header, &lv_flex_row_center); lv_obj_set_flex_flow(header, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_place(header, LV_FLEX_PLACE_START, LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_START);
lv_obj_t * year_dd = lv_dropdown_create(header, NULL); lv_obj_t * year_dd = lv_dropdown_create(header, NULL);
lv_dropdown_set_options(year_dd, year_list); lv_dropdown_set_options(year_dd, year_list);
lv_dropdown_set_selected(year_dd, 2023 - cur_date->year); lv_dropdown_set_selected(year_dd, 2023 - cur_date->year);
lv_obj_add_event_cb(year_dd, year_event_cb, calendar); lv_obj_add_event_cb(year_dd, year_event_cb, calendar);
lv_obj_set_flex_grow(year_dd, 1); lv_obj_set_flex_grow(year_dd, 1);
lv_obj_clear_flag(year_dd, LV_OBJ_FLAG_CLICK_FOCUSABLE);
lv_obj_t * month_dd = lv_dropdown_create(header, NULL); lv_obj_t * month_dd = lv_dropdown_create(header, NULL);
lv_dropdown_set_options(month_dd, month_list); lv_dropdown_set_options(month_dd, month_list);
lv_dropdown_set_selected(month_dd, cur_date->month - 1); lv_dropdown_set_selected(month_dd, cur_date->month - 1);
lv_obj_add_event_cb(month_dd, month_event_cb, calendar); lv_obj_add_event_cb(month_dd, month_event_cb, calendar);
lv_obj_set_flex_grow(month_dd, 1); lv_obj_set_flex_grow(month_dd, 1);
lv_obj_clear_flag(month_dd, LV_OBJ_FLAG_CLICK_FOCUSABLE);
lv_obj_align(header, calendar, LV_ALIGN_OUT_TOP_MID, 0, 0); lv_obj_align(header, calendar, LV_ALIGN_OUT_TOP_MID, 0, 0);

View File

@@ -355,7 +355,7 @@ static void lv_colorwheel_event(lv_obj_t * obj, lv_event_t e)
lv_coord_t * s = lv_event_get_param(); lv_coord_t * s = lv_event_get_param();
*s = LV_MAX(*s, knob_pad); *s = LV_MAX(*s, knob_pad);
} }
else if(e == LV_EVENT_COORD_CHANGED) { else if(e == LV_EVENT_SIZE_CHANGED) {
void * param = lv_event_get_param(); void * param = lv_event_get_param();
/*Refresh extended draw area to make knob visible*/ /*Refresh extended draw area to make knob visible*/
if(lv_obj_get_width(obj) != lv_area_get_width(param) || if(lv_obj_get_width(obj) != lv_area_get_width(param) ||

View File

@@ -55,7 +55,7 @@ lv_obj_t * lv_list_create(lv_obj_t * parent)
{ {
lv_obj_t * list = lv_obj_create_from_class(&lv_list_class, parent, NULL); lv_obj_t * list = lv_obj_create_from_class(&lv_list_class, parent, NULL);
lv_obj_set_size(list, LV_DPX(200), LV_DPX(300)); lv_obj_set_size(list, LV_DPX(200), LV_DPX(300));
lv_obj_set_layout(list, &lv_flex_column_nowrap); lv_obj_set_flex_flow(list, LV_FLEX_FLOW_COLUMN);
return list; return list;
} }
@@ -74,7 +74,6 @@ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const char * icon, const char * txt,
lv_obj_t * btn = lv_obj_create_from_class(&lv_list_btn_class, list, NULL); lv_obj_t * btn = lv_obj_create_from_class(&lv_list_btn_class, list, NULL);
lv_obj_set_size(btn, LV_SIZE_PCT(100), LV_SIZE_CONTENT); lv_obj_set_size(btn, LV_SIZE_PCT(100), LV_SIZE_CONTENT);
lv_obj_add_event_cb(btn, event_cb, NULL); lv_obj_add_event_cb(btn, event_cb, NULL);
lv_obj_set_layout(btn, &lv_flex_row_wrap);
if(icon) { if(icon) {
lv_obj_t * img = lv_img_create(btn, NULL); lv_obj_t * img = lv_img_create(btn, NULL);

View File

@@ -60,7 +60,7 @@ lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * b
if(w > 2 * LV_DPI_DEF) w = 2 * LV_DPI_DEF; if(w > 2 * LV_DPI_DEF) w = 2 * LV_DPI_DEF;
lv_obj_set_size(mbox, w, LV_SIZE_CONTENT); lv_obj_set_size(mbox, w, LV_SIZE_CONTENT);
lv_obj_set_layout(mbox, &lv_flex_row_wrap); lv_obj_set_flex_flow(mbox, LV_FLEX_FLOW_ROW);
lv_obj_t * label; lv_obj_t * label;
label = lv_label_create(mbox, NULL); label = lv_label_create(mbox, NULL);

View File

@@ -151,25 +151,23 @@ static void lv_tabview_constructor(lv_obj_t * obj, const lv_obj_t * copy)
lv_tabview_t * tabview = (lv_tabview_t *)obj; lv_tabview_t * tabview = (lv_tabview_t *)obj;
tabview->tab_pos = tabpos_create; tabview->tab_pos = tabpos_create;
lv_flex_init(&tabview->flex);
switch(tabview->tab_pos) { switch(tabview->tab_pos) {
case LV_DIR_TOP: case LV_DIR_TOP:
lv_flex_set_flow(&tabview->flex, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);
break; break;
case LV_DIR_BOTTOM: case LV_DIR_BOTTOM:
lv_flex_set_flow(&tabview->flex, LV_FLEX_FLOW_COLUMN_REVERSE); lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN_REVERSE);
break; break;
case LV_DIR_LEFT: case LV_DIR_LEFT:
lv_flex_set_flow(&tabview->flex, LV_FLEX_FLOW_ROW); lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW);
break; break;
case LV_DIR_RIGHT: case LV_DIR_RIGHT:
lv_flex_set_flow(&tabview->flex, LV_FLEX_FLOW_ROW_REVERSE); lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW_REVERSE);
break; break;
} }
lv_obj_set_size(obj, LV_SIZE_PCT(100), LV_SIZE_PCT(100)); lv_obj_set_size(obj, LV_SIZE_PCT(100), LV_SIZE_PCT(100));
lv_obj_set_layout(obj, &tabview->flex);
lv_obj_t * btnm; lv_obj_t * btnm;
lv_obj_t * cont; lv_obj_t * cont;
@@ -202,7 +200,7 @@ static void lv_tabview_constructor(lv_obj_t * obj, const lv_obj_t * copy)
break; break;
} }
lv_obj_set_layout(cont, &lv_flex_row_nowrap); lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW);
lv_obj_set_scroll_snap_x(cont, LV_SCROLL_SNAP_CENTER); lv_obj_set_scroll_snap_x(cont, LV_SCROLL_SNAP_CENTER);
lv_obj_add_flag(cont, LV_OBJ_FLAG_SCROLL_ONE); lv_obj_add_flag(cont, LV_OBJ_FLAG_SCROLL_ONE);
lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLL_ON_FOCUS); lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLL_ON_FOCUS);

View File

@@ -29,7 +29,6 @@ typedef struct
{ {
lv_obj_t obj; lv_obj_t obj;
char ** map; char ** map;
lv_flex_t flex;
uint16_t tab_cnt; uint16_t tab_cnt;
uint16_t tab_cur; uint16_t tab_cur;
lv_dir_t tab_pos; lv_dir_t tab_pos;

View File

@@ -85,11 +85,11 @@ static void lv_win_constructor(lv_obj_t * obj, const lv_obj_t * copy)
LV_UNUSED(copy); LV_UNUSED(copy);
lv_obj_t * parent = lv_obj_get_parent(obj); lv_obj_t * parent = lv_obj_get_parent(obj);
lv_obj_set_size(obj, lv_obj_get_width(parent), lv_obj_get_height(parent)); lv_obj_set_size(obj, lv_obj_get_width(parent), lv_obj_get_height(parent));
lv_obj_set_layout(obj, &lv_flex_column_nowrap); lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);
lv_obj_t * header = lv_obj_create(obj, NULL); lv_obj_t * header = lv_obj_create(obj, NULL);
lv_obj_set_size(header, LV_SIZE_PCT(100), create_header_height); lv_obj_set_size(header, LV_SIZE_PCT(100), create_header_height);
lv_obj_set_layout(header, &lv_flex_row_wrap); lv_obj_set_flex_flow(header, LV_FLEX_FLOW_ROW);
lv_obj_t * cont = lv_obj_create(obj, NULL); lv_obj_t * cont = lv_obj_create(obj, NULL);
lv_obj_set_flex_grow(cont, 1); lv_obj_set_flex_grow(cont, 1);

View File

@@ -169,7 +169,7 @@ void lv_disp_drv_update(lv_disp_t * disp, lv_disp_drv_t * new_drv)
lv_obj_get_coords(disp->screens[i], &prev_coords); lv_obj_get_coords(disp->screens[i], &prev_coords);
lv_area_set_width(&disp->screens[i]->coords, w); lv_area_set_width(&disp->screens[i]->coords, w);
lv_area_set_height(&disp->screens[i]->coords, h); lv_area_set_height(&disp->screens[i]->coords, h);
lv_event_send(disp->screens[i], LV_EVENT_COORD_CHANGED, &prev_coords); lv_event_send(disp->screens[i], LV_EVENT_SIZE_CHANGED, &prev_coords);
} }
/* /*

View File

@@ -234,22 +234,18 @@ void _lv_area_align(const lv_area_t * base, const lv_area_t * to_align, lv_align
#define _LV_COORD_TYPE_PX (0 << _LV_COORD_TYPE_SHIFT) #define _LV_COORD_TYPE_PX (0 << _LV_COORD_TYPE_SHIFT)
#define _LV_COORD_TYPE_SPEC (1 << _LV_COORD_TYPE_SHIFT) #define _LV_COORD_TYPE_SPEC (1 << _LV_COORD_TYPE_SHIFT)
#define _LV_COORD_TYPE_LAYOUT (2 << _LV_COORD_TYPE_SHIFT)
#define _LV_COORD_TYPE_RESERVED (3 << _LV_COORD_TYPE_SHIFT) #define _LV_COORD_TYPE_RESERVED (3 << _LV_COORD_TYPE_SHIFT)
#define LV_COORD_IS_PX(x) ((((x) & _LV_COORD_TYPE_MASK) == _LV_COORD_TYPE_PX) ? true : false) #define LV_COORD_IS_PX(x) ((((x) & _LV_COORD_TYPE_MASK) == _LV_COORD_TYPE_PX) ? true : false)
#define LV_COORD_IS_SPEC(x) ((((x) & _LV_COORD_TYPE_MASK) == _LV_COORD_TYPE_SPEC) ? true : false) #define LV_COORD_IS_SPEC(x) ((((x) & _LV_COORD_TYPE_MASK) == _LV_COORD_TYPE_SPEC) ? true : false)
#define LV_COORD_IS_LAYOUT(x) ((((x) & _LV_COORD_TYPE_MASK) == _LV_COORD_TYPE_LAYOUT) ? true : false)
#define LV_COORD_SET_SPEC(x) ((x) | _LV_COORD_TYPE_SPEC) #define LV_COORD_SET_SPEC(x) ((x) | _LV_COORD_TYPE_SPEC)
#define LV_COORD_SET_LAYOUT(x) ((x) | _LV_COORD_TYPE_LAYOUT)
/*Special coordinates*/ /*Special coordinates*/
#define LV_SIZE_PCT(x) LV_COORD_SET_SPEC(x) #define LV_SIZE_PCT(x) LV_COORD_SET_SPEC(x)
#define LV_COORD_IS_PCT(x) ((LV_COORD_IS_SPEC(x) && _LV_COORD_PLAIN(x) <= 1000) ? true : false) #define LV_COORD_IS_PCT(x) ((LV_COORD_IS_SPEC(x) && _LV_COORD_PLAIN(x) <= 1000) ? true : false)
#define LV_COORD_GET_PCT(x) _LV_COORD_PLAIN(x) #define LV_COORD_GET_PCT(x) _LV_COORD_PLAIN(x)
#define LV_SIZE_CONTENT LV_COORD_SET_SPEC(1001) #define LV_SIZE_CONTENT LV_COORD_SET_SPEC(1001)
#define LV_SIZE_LAYOUT LV_COORD_SET_SPEC(1002) /*The size is managed by the layout therefore `lv_obj_set_width/height/size()` can't change is*/
#ifdef __cplusplus #ifdef __cplusplus
} /*extern "C"*/ } /*extern "C"*/

View File

@@ -23,7 +23,7 @@
*********************/ *********************/
/*Add memory junk on alloc (0xaa) and free(0xbb) (just for testing purposes)*/ /*Add memory junk on alloc (0xaa) and free(0xbb) (just for testing purposes)*/
#ifndef LV_MEM_ADD_JUNK #ifndef LV_MEM_ADD_JUNK
# define LV_MEM_ADD_JUNK 0 # define LV_MEM_ADD_JUNK 1
#endif #endif
#ifdef LV_ARCH_64 #ifdef LV_ARCH_64

View File

@@ -30,6 +30,8 @@
// //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/*Original repository: https://github.com/mpaland/printf*/
#include "lv_printf.h" #include "lv_printf.h"
#if LV_SPRINTF_CUSTOM == 0 #if LV_SPRINTF_CUSTOM == 0

View File

@@ -29,6 +29,8 @@
// //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/*Original repository: https://github.com/mpaland/printf*/
#ifndef _LV_PRINTF_H_ #ifndef _LV_PRINTF_H_
#define _LV_PRINTF_H_ #define _LV_PRINTF_H_

View File

@@ -188,7 +188,7 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_
style->has_group |= 1 << group; style->has_group |= 1 << group;
} }
bool lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value) lv_res_t lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value)
{ {
return lv_style_get_prop_inlined(style, prop, value); return lv_style_get_prop_inlined(style, prop, value);
} }

View File

@@ -134,6 +134,12 @@ typedef enum {
LV_STYLE_PAD_ROW = 20 | LV_STYLE_PROP_LAYOUT_REFR, LV_STYLE_PAD_ROW = 20 | LV_STYLE_PROP_LAYOUT_REFR,
LV_STYLE_PAD_COLUMN = 21 | LV_STYLE_PROP_LAYOUT_REFR, LV_STYLE_PAD_COLUMN = 21 | LV_STYLE_PROP_LAYOUT_REFR,
LV_STYLE_WIDTH = 22 | LV_STYLE_PROP_LAYOUT_REFR,
LV_STYLE_HEIGHT = 23 | LV_STYLE_PROP_LAYOUT_REFR,
LV_STYLE_X = 24 | LV_STYLE_PROP_LAYOUT_REFR,
LV_STYLE_Y = 25 | LV_STYLE_PROP_LAYOUT_REFR,
LV_STYLE_LAYOUT = 26 | LV_STYLE_PROP_LAYOUT_REFR,
/*Group 2*/ /*Group 2*/
LV_STYLE_BG_COLOR = 32, LV_STYLE_BG_COLOR = 32,
LV_STYLE_BG_COLOR_FILTERED = 32 | LV_STYLE_PROP_FILTER, LV_STYLE_BG_COLOR_FILTERED = 32 | LV_STYLE_PROP_FILTER,
@@ -318,11 +324,11 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_
* @param style pointer to a style * @param style pointer to a style
* @param prop the ID of a property * @param prop the ID of a property
* @param value pointer to a `lv_style_value_t` variable to store the value * @param value pointer to a `lv_style_value_t` variable to store the value
* @return false: the property wsn't found in the style (`value` is unchanged) * @return LV_RES_INV: the property wsn't found in the style (`value` is unchanged)
* true: the property was fond, and `value` is set accordingly * LV_RES_OK: the property was fond, and `value` is set accordingly
* @note For performance reasons there are no sanity check on `style` * @note For performance reasons there are no sanity check on `style`
*/ */
bool lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value); lv_res_t lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value);
/** /**
@@ -330,14 +336,14 @@ bool lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_
* @param style pointer to a style * @param style pointer to a style
* @param prop the ID of a property * @param prop the ID of a property
* @param value pointer to a `lv_style_value_t` variable to store the value * @param value pointer to a `lv_style_value_t` variable to store the value
* @return false: the property wsn't found in the style (`value` is unchanged) * @return LV_RES_INV: the property wsn't found in the style (`value` is unchanged)
* true: the property was fond, and `value` is set accordingly * LV_RES_OK: the property was fond, and `value` is set accordingly
* @note For performance reasons there are no sanity check on `style` * @note For performance reasons there are no sanity check on `style`
* @note This function is the same as ::lv_style_get_prop but inlined. Use it only on performance critical places * @note This function is the same as ::lv_style_get_prop but inlined. Use it only on performance critical places
*/ */
static inline bool lv_style_get_prop_inlined(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value) static inline lv_res_t lv_style_get_prop_inlined(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value)
{ {
if(style->prop_cnt == 0) return false; if(style->prop_cnt == 0) return LV_RES_INV;
if(style->prop_cnt > 1) { if(style->prop_cnt > 1) {
uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t); uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
@@ -347,14 +353,14 @@ static inline bool lv_style_get_prop_inlined(lv_style_t * style, lv_style_prop_t
if(props[i] == prop) { if(props[i] == prop) {
lv_style_value_t * values = (lv_style_value_t *)style->v_p.values_and_props; lv_style_value_t * values = (lv_style_value_t *)style->v_p.values_and_props;
*value = values[i]; *value = values[i];
return true; return LV_RES_OK;
} }
} }
} else if(style->prop1 == prop) { } else if(style->prop1 == prop) {
*value = style->v_p.value1; *value = style->v_p.value1;
return true; return true;
} }
return false; return LV_RES_INV;
} }
/** /**

View File

@@ -150,6 +150,48 @@ static inline void lv_style_set_pad_column(lv_style_t * style, lv_coord_t value)
lv_style_set_prop(style, LV_STYLE_PAD_COLUMN, v); lv_style_set_prop(style, LV_STYLE_PAD_COLUMN, v);
} }
static inline void lv_style_set_width(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_WIDTH, v);
}
static inline void lv_style_set_height(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_HEIGHT, v);
}
static inline void lv_style_set_x(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_X, v);
}
static inline void lv_style_set_y(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_Y, v);
}
static inline void lv_style_set_layout(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_LAYOUT, v);
}
static inline void lv_style_set_bg_color(lv_style_t * style, lv_color_t value) static inline void lv_style_set_bg_color(lv_style_t * style, lv_color_t value)
{ {
lv_style_value_t v = { lv_style_value_t v = {

View File

@@ -502,8 +502,6 @@ static void lv_arc_constructor(lv_obj_t * obj, const lv_obj_t * copy)
arc->last_tick = lv_tick_get(); arc->last_tick = lv_tick_get();
arc->last_angle =arc->indic_angle_end; arc->last_angle =arc->indic_angle_end;
lv_obj_set_size(obj, LV_DPI_DEF, LV_DPI_DEF);
/*Init the new arc arc*/ /*Init the new arc arc*/
if(copy == NULL) { if(copy == NULL) {
lv_obj_add_flag(obj, LV_OBJ_FLAG_CLICKABLE); lv_obj_add_flag(obj, LV_OBJ_FLAG_CLICKABLE);

View File

@@ -122,7 +122,7 @@ void lv_bar_set_range(lv_obj_t * obj, int16_t min, int16_t max)
bar->max_value = max; bar->max_value = max;
bar->min_value = min; bar->min_value = min;
if(lv_bar_get_type(obj) != LV_BAR_TYPE_RANGE) if(lv_bar_get_mode(obj) != LV_BAR_MODE_RANGE)
bar->start_value = min; bar->start_value = min;
if(bar->cur_value > max) { if(bar->cur_value > max) {
@@ -136,13 +136,13 @@ void lv_bar_set_range(lv_obj_t * obj, int16_t min, int16_t max)
lv_obj_invalidate(obj); lv_obj_invalidate(obj);
} }
void lv_bar_set_type(lv_obj_t * obj, lv_bar_type_t type) void lv_bar_set_mode(lv_obj_t * obj, lv_bar_mode_t mode)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
lv_bar_t * bar = (lv_bar_t *)obj; lv_bar_t * bar = (lv_bar_t *)obj;
bar->type = type; bar->mode = mode;
if(bar->type != LV_BAR_TYPE_RANGE) { if(bar->mode != LV_BAR_MODE_RANGE) {
bar->start_value = bar->min_value; bar->start_value = bar->min_value;
} }
@@ -166,7 +166,7 @@ int16_t lv_bar_get_start_value(const lv_obj_t * obj)
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
lv_bar_t * bar = (lv_bar_t *)obj; lv_bar_t * bar = (lv_bar_t *)obj;
if(bar->type != LV_BAR_TYPE_RANGE) return bar->min_value; if(bar->mode != LV_BAR_MODE_RANGE) return bar->min_value;
return LV_BAR_GET_ANIM_VALUE(bar->start_value, bar->start_value_anim); return LV_BAR_GET_ANIM_VALUE(bar->start_value, bar->start_value_anim);
} }
@@ -186,12 +186,12 @@ int16_t lv_bar_get_max_value(const lv_obj_t * obj)
return bar->max_value; return bar->max_value;
} }
lv_bar_type_t lv_bar_get_type(lv_obj_t * obj) lv_bar_mode_t lv_bar_get_mode(lv_obj_t * obj)
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
lv_bar_t * bar = (lv_bar_t *)obj; lv_bar_t * bar = (lv_bar_t *)obj;
return bar->type; return bar->mode;
} }
/********************** /**********************
@@ -207,7 +207,7 @@ static void lv_bar_constructor(lv_obj_t * obj, const lv_obj_t * copy)
bar->max_value = 100; bar->max_value = 100;
bar->start_value = 0; bar->start_value = 0;
bar->cur_value = 0; bar->cur_value = 0;
bar->type = LV_BAR_TYPE_NORMAL; bar->mode = LV_BAR_MODE_NORMAL;
lv_bar_init_anim(obj, &bar->cur_value_anim); lv_bar_init_anim(obj, &bar->cur_value_anim);
lv_bar_init_anim(obj, &bar->start_value_anim); lv_bar_init_anim(obj, &bar->start_value_anim);
@@ -223,7 +223,7 @@ static void lv_bar_constructor(lv_obj_t * obj, const lv_obj_t * copy)
bar->start_value = copy_bar->start_value; bar->start_value = copy_bar->start_value;
bar->max_value = copy_bar->max_value; bar->max_value = copy_bar->max_value;
bar->cur_value = copy_bar->cur_value; bar->cur_value = copy_bar->cur_value;
bar->type = copy_bar->type; bar->mode = copy_bar->mode;
lv_bar_set_value(obj, bar->cur_value, LV_ANIM_OFF); lv_bar_set_value(obj, bar->cur_value, LV_ANIM_OFF);
} }
@@ -258,7 +258,7 @@ static void draw_indic(lv_obj_t * obj)
int32_t range = bar->max_value - bar->min_value; int32_t range = bar->max_value - bar->min_value;
bool hor = barw >= barh ? true : false; bool hor = barw >= barh ? true : false;
bool sym = false; bool sym = false;
if(bar->type == LV_BAR_TYPE_SYMMETRICAL && bar->min_value < 0 && bar->max_value > 0 && if(bar->mode == LV_BAR_MODE_SYMMETRICAL && bar->min_value < 0 && bar->max_value > 0 &&
bar->start_value == bar->min_value) sym = true; bar->start_value == bar->min_value) sym = true;
/*Calculate the indicator area*/ /*Calculate the indicator area*/

View File

@@ -31,11 +31,11 @@ extern "C" {
**********************/ **********************/
enum { enum {
LV_BAR_TYPE_NORMAL, LV_BAR_MODE_NORMAL,
LV_BAR_TYPE_SYMMETRICAL, LV_BAR_MODE_SYMMETRICAL,
LV_BAR_TYPE_RANGE LV_BAR_MODE_RANGE
}; };
typedef uint8_t lv_bar_type_t; typedef uint8_t lv_bar_mode_t;
typedef struct { typedef struct {
lv_obj_t * bar; lv_obj_t * bar;
@@ -53,7 +53,7 @@ typedef struct {
lv_area_t indic_area; /**< Save the indicator area. Might be used by derived types*/ lv_area_t indic_area; /**< Save the indicator area. Might be used by derived types*/
lv_bar_anim_t cur_value_anim; lv_bar_anim_t cur_value_anim;
lv_bar_anim_t start_value_anim; lv_bar_anim_t start_value_anim;
lv_bar_type_t type : 2; /**< Type of bar*/ lv_bar_mode_t mode : 2; /**< Type of bar*/
}lv_bar_t; }lv_bar_t;
extern const lv_obj_class_t lv_bar_class; extern const lv_obj_class_t lv_bar_class;
@@ -102,9 +102,9 @@ void lv_bar_set_range(lv_obj_t * obj, int16_t min, int16_t max);
/** /**
* Set the type of bar. * Set the type of bar.
* @param obj pointer to bar object * @param obj pointer to bar object
* @param type bar type from ::lv_bar_type_t * @param mode bar type from ::lv_bar_mode_t
*/ */
void lv_bar_set_type(lv_obj_t * obj, lv_bar_type_t type); void lv_bar_set_mode(lv_obj_t * obj, lv_bar_mode_t mode);
/*===================== /*=====================
* Getter functions * Getter functions
@@ -141,9 +141,9 @@ int16_t lv_bar_get_max_value(const lv_obj_t * obj);
/** /**
* Get the type of bar. * Get the type of bar.
* @param obj pointer to bar object * @param obj pointer to bar object
* @return bar type from ::lv_bar_type_t * @return bar type from ::lv_bar_mode_t
*/ */
lv_bar_type_t lv_bar_get_type(lv_obj_t * obj); lv_bar_mode_t lv_bar_get_mode(lv_obj_t * obj);
/********************** /**********************
* MACROS * MACROS

View File

@@ -60,10 +60,6 @@ static void lv_btn_constructor(lv_obj_t * obj, const lv_obj_t * copy)
lv_obj_set_size(obj, LV_DPI_DEF, LV_DPI_DEF / 3); lv_obj_set_size(obj, LV_DPI_DEF, LV_DPI_DEF / 3);
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE); lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS); lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
#if LV_USE_FLEX
lv_obj_set_layout(obj, &lv_flex_row_center);
#endif
} }
LV_TRACE_OBJ_CREATE("finished"); LV_TRACE_OBJ_CREATE("finished");

View File

@@ -84,7 +84,7 @@ lv_obj_t * lv_btnmatrix_create(lv_obj_t * parent, const lv_obj_t * copy)
void lv_btnmatrix_set_map(lv_obj_t * obj, const char * map[]) void lv_btnmatrix_set_map(lv_obj_t * obj, const char * map[])
{ {
LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_OBJ(obj, MY_CLASS);
LV_ASSERT_NULL(map); if(map == NULL) return;
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;; lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;;
@@ -403,13 +403,8 @@ static void lv_btnmatrix_event(lv_obj_t * obj, lv_event_t e)
if(e == LV_EVENT_STYLE_CHANGED) { if(e == LV_EVENT_STYLE_CHANGED) {
lv_btnmatrix_set_map(obj, btnm->map_p); lv_btnmatrix_set_map(obj, btnm->map_p);
} }
else if(e == LV_EVENT_COORD_CHANGED) { else if(e == LV_EVENT_SIZE_CHANGED) {
void * param = lv_event_get_param(); lv_btnmatrix_set_map(obj, btnm->map_p);
if(param &&
(lv_obj_get_width(obj) != lv_area_get_width(param) || lv_obj_get_height(obj) != lv_area_get_height(param)))
{
lv_btnmatrix_set_map(obj, btnm->map_p);
}
} }
else if(e == LV_EVENT_PRESSED) { else if(e == LV_EVENT_PRESSED) {
void * param = lv_event_get_param(); void * param = lv_event_get_param();

View File

@@ -429,6 +429,8 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj)
((lv_dropdown_list_t*) list_obj)->dropdown = dropdown_obj; ((lv_dropdown_list_t*) list_obj)->dropdown = dropdown_obj;
dropdown->list = list_obj; dropdown->list = list_obj;
lv_obj_clear_flag(dropdown->list, LV_OBJ_FLAG_CLICK_FOCUSABLE); lv_obj_clear_flag(dropdown->list, LV_OBJ_FLAG_CLICK_FOCUSABLE);
lv_obj_add_flag(dropdown->list, LV_OBJ_FLAG_IGNORE_LAYOUT);
lv_obj_update_layout(dropdown->list);
} }
lv_obj_t * label = get_label(dropdown_obj); lv_obj_t * label = get_label(dropdown_obj);
@@ -441,7 +443,6 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj)
lv_obj_set_width(dropdown->list, lv_obj_get_width(dropdown_obj)); lv_obj_set_width(dropdown->list, lv_obj_get_width(dropdown_obj));
} }
lv_coord_t label_h = lv_obj_get_height(label); lv_coord_t label_h = lv_obj_get_height(label);
lv_coord_t top = lv_obj_get_style_pad_top(dropdown->list, LV_PART_MAIN); lv_coord_t top = lv_obj_get_style_pad_top(dropdown->list, LV_PART_MAIN);
lv_coord_t bottom = lv_obj_get_style_pad_bottom(dropdown->list, LV_PART_MAIN); lv_coord_t bottom = lv_obj_get_style_pad_bottom(dropdown->list, LV_PART_MAIN);
@@ -490,9 +491,12 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj)
else if(dir == LV_DIR_LEFT) lv_obj_align(dropdown->list, dropdown_obj, LV_ALIGN_OUT_LEFT_TOP, 0, 0); else if(dir == LV_DIR_LEFT) lv_obj_align(dropdown->list, dropdown_obj, LV_ALIGN_OUT_LEFT_TOP, 0, 0);
else if(dir == LV_DIR_RIGHT) lv_obj_align(dropdown->list, dropdown_obj, LV_ALIGN_OUT_RIGHT_TOP, 0, 0); else if(dir == LV_DIR_RIGHT) lv_obj_align(dropdown->list, dropdown_obj, LV_ALIGN_OUT_RIGHT_TOP, 0, 0);
if(dropdown->dir == LV_DIR_LEFT || dropdown->dir == LV_DIR_RIGHT) { if(dropdown->dir == LV_DIR_LEFT || dropdown->dir == LV_DIR_RIGHT) {
if(dropdown->list->coords.y2 >= LV_VER_RES) { lv_coord_t y1 = lv_obj_get_y(dropdown->list);
lv_obj_set_y(dropdown->list, lv_obj_get_y(dropdown->list) - (dropdown->list->coords.y2 - LV_VER_RES) - 1); lv_coord_t y2 = lv_obj_get_y2(dropdown->list);
if(y2 >= LV_VER_RES) {
lv_obj_set_y(dropdown->list, y1 - (y2 - LV_VER_RES) - 1);
} }
} }
@@ -662,7 +666,7 @@ static void lv_dropdown_event(lv_obj_t * obj, lv_event_t e)
lv_obj_invalidate(obj); lv_obj_invalidate(obj);
} }
} }
else if(e == LV_EVENT_COORD_CHANGED) { else if(e == LV_EVENT_SIZE_CHANGED) {
if(dropdown->list) lv_dropdown_close(obj); if(dropdown->list) lv_dropdown_close(obj);
} }
else if(e == LV_EVENT_GET_SELF_SIZE) { else if(e == LV_EVENT_GET_SELF_SIZE) {

View File

@@ -750,13 +750,9 @@ static void lv_label_event_cb(lv_obj_t * obj, lv_event_t e)
lv_label_revert_dots(obj); lv_label_revert_dots(obj);
lv_label_refr_text(obj); lv_label_refr_text(obj);
} }
else if(e == LV_EVENT_COORD_CHANGED) { else if(e == LV_EVENT_SIZE_CHANGED) {
void * param = lv_event_get_param(); lv_label_revert_dots(obj);
if(lv_area_get_width(&obj->coords) != lv_area_get_width(param) || lv_label_refr_text(obj);
lv_area_get_height(&obj->coords) != lv_area_get_height(param)) {
lv_label_revert_dots(obj);
lv_label_refr_text(obj);
}
} }
else if(e == LV_EVENT_BASE_DIR_CHANGED) { else if(e == LV_EVENT_BASE_DIR_CHANGED) {
#if LV_USE_BIDI #if LV_USE_BIDI

View File

@@ -334,13 +334,8 @@ static void lv_roller_event(lv_obj_t * obj, lv_event_t e)
lv_obj_handle_self_size_chg(obj); lv_obj_handle_self_size_chg(obj);
refr_position(obj, false); refr_position(obj, false);
} }
else if(e == LV_EVENT_COORD_CHANGED) { else if(e == LV_EVENT_SIZE_CHANGED) {
void * param = lv_event_get_param(); refr_position(obj, false);
if(lv_obj_get_width(obj) != lv_area_get_width(param) ||
lv_obj_get_height(obj) != lv_area_get_height(param))
{
refr_position(obj, false);
}
} }
else if(e == LV_EVENT_PRESSED) { else if(e == LV_EVENT_PRESSED) {
roller->moved = 0; roller->moved = 0;

View File

@@ -105,7 +105,7 @@ static void lv_slider_event(lv_obj_t * obj, lv_event_t e)
if(res != LV_RES_OK) return; if(res != LV_RES_OK) return;
lv_slider_t * slider = (lv_slider_t *)obj; lv_slider_t * slider = (lv_slider_t *)obj;
lv_slider_type_t type = lv_slider_get_type(obj); lv_slider_mode_t type = lv_slider_get_mode(obj);
/*Advanced hit testing: react only on dragging the knob(s)*/ /*Advanced hit testing: react only on dragging the knob(s)*/
if(e == LV_EVENT_HIT_TEST) { if(e == LV_EVENT_HIT_TEST) {
@@ -115,17 +115,17 @@ static void lv_slider_event(lv_obj_t * obj, lv_event_t e)
info->result = _lv_area_is_point_on(&slider->right_knob_area, info->point, 0); info->result = _lv_area_is_point_on(&slider->right_knob_area, info->point, 0);
/*There's still a change we have a hit, if we have another knob*/ /*There's still a change we have a hit, if we have another knob*/
if((info->result == false) && (type == LV_SLIDER_TYPE_RANGE)) { if((info->result == false) && (type == LV_SLIDER_MODE_RANGE)) {
info->result = _lv_area_is_point_on(&slider->left_knob_area, info->point, 0); info->result = _lv_area_is_point_on(&slider->left_knob_area, info->point, 0);
} }
} }
else if(e == LV_EVENT_PRESSED) { else if(e == LV_EVENT_PRESSED) {
lv_point_t p; lv_point_t p;
slider->dragging = true; slider->dragging = true;
if(type == LV_SLIDER_TYPE_NORMAL || type == LV_SLIDER_TYPE_SYMMETRICAL) { if(type == LV_SLIDER_MODE_NORMAL || type == LV_SLIDER_MODE_SYMMETRICAL) {
slider->value_to_set = &slider->bar.cur_value; slider->value_to_set = &slider->bar.cur_value;
} }
else if(type == LV_SLIDER_TYPE_RANGE) { else if(type == LV_SLIDER_MODE_RANGE) {
lv_indev_get_point(lv_indev_get_act(), &p); lv_indev_get_point(lv_indev_get_act(), &p);
bool hor = lv_obj_get_width(obj) >= lv_obj_get_height(obj); bool hor = lv_obj_get_width(obj) >= lv_obj_get_height(obj);
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(obj); lv_bidi_dir_t base_dir = lv_obj_get_base_dir(obj);
@@ -249,7 +249,7 @@ static void lv_slider_event(lv_obj_t * obj, lv_event_t e)
lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
if(indev_type == LV_INDEV_TYPE_ENCODER) { if(indev_type == LV_INDEV_TYPE_ENCODER) {
if(editing) { if(editing) {
if(lv_slider_get_type(obj) == LV_SLIDER_TYPE_RANGE) { if(lv_slider_get_mode(obj) == LV_SLIDER_MODE_RANGE) {
if(slider->left_knob_focus == 0) slider->left_knob_focus = 1; if(slider->left_knob_focus == 0) slider->left_knob_focus = 1;
else { else {
slider->left_knob_focus = 0; slider->left_knob_focus = 0;
@@ -269,14 +269,8 @@ static void lv_slider_event(lv_obj_t * obj, lv_event_t e)
slider->left_knob_focus = 0; slider->left_knob_focus = 0;
} }
} }
else if(e == LV_EVENT_COORD_CHANGED) { else if(e == LV_EVENT_SIZE_CHANGED) {
/*The knob size depends on slider size. lv_obj_refresh_ext_draw_size(obj);
*During the drawing method the obj. size is used by the knob so refresh the obj. size.*/
void * param = lv_event_get_param();
if(lv_obj_get_width(obj) != lv_area_get_width(param) ||
lv_obj_get_height(obj) != lv_area_get_height(param)) {
lv_obj_refresh_ext_draw_size(obj);
}
} }
else if(e == LV_EVENT_REFR_EXT_DRAW_SIZE) { else if(e == LV_EVENT_REFR_EXT_DRAW_SIZE) {
lv_coord_t knob_left = lv_obj_get_style_pad_left(obj, LV_PART_KNOB); lv_coord_t knob_left = lv_obj_get_style_pad_left(obj, LV_PART_KNOB);
@@ -331,7 +325,7 @@ static void draw_knob(lv_obj_t * obj)
bool hor = objw >= objh ? true : false; bool hor = objw >= objh ? true : false;
lv_coord_t knob_size = hor ? objh : objw; lv_coord_t knob_size = hor ? objh : objw;
bool sym = false; bool sym = false;
if(slider->bar.type == LV_BAR_TYPE_SYMMETRICAL && slider->bar.min_value < 0 && slider->bar.max_value > 0) sym = true; if(slider->bar.mode == LV_BAR_MODE_SYMMETRICAL && slider->bar.min_value < 0 && slider->bar.max_value > 0) sym = true;
lv_area_t knob_area; lv_area_t knob_area;
@@ -378,7 +372,7 @@ static void draw_knob(lv_obj_t * obj)
dsc.draw_area = &slider->right_knob_area; dsc.draw_area = &slider->right_knob_area;
dsc.rect_dsc = &knob_rect_dsc; dsc.rect_dsc = &knob_rect_dsc;
if(lv_slider_get_type(obj) != LV_SLIDER_TYPE_RANGE) { if(lv_slider_get_mode(obj) != LV_SLIDER_MODE_RANGE) {
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc); lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc);
lv_draw_rect(&slider->right_knob_area, clip_area, &knob_rect_dsc); lv_draw_rect(&slider->right_knob_area, clip_area, &knob_rect_dsc);
lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc); lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc);

View File

@@ -34,11 +34,11 @@ extern "C" {
**********************/ **********************/
enum { enum {
LV_SLIDER_TYPE_NORMAL = LV_BAR_TYPE_NORMAL, LV_SLIDER_MODE_NORMAL = LV_BAR_MODE_NORMAL,
LV_SLIDER_TYPE_SYMMETRICAL = LV_BAR_TYPE_SYMMETRICAL, LV_SLIDER_MODE_SYMMETRICAL = LV_BAR_MODE_SYMMETRICAL,
LV_SLIDER_TYPE_RANGE = LV_BAR_TYPE_RANGE LV_SLIDER_MODE_RANGE = LV_BAR_MODE_RANGE
}; };
typedef uint8_t lv_slider_type_t; typedef uint8_t lv_slider_mode_t;
typedef struct { typedef struct {
lv_bar_t bar; /*Add the ancestor's type first*/ lv_bar_t bar; /*Add the ancestor's type first*/
@@ -102,13 +102,13 @@ static inline void lv_slider_set_range(lv_obj_t * obj, int16_t min, int16_t max)
} }
/** /**
* Set the type of slider. * Set the mode of slider.
* @param obj pointer to a slider object * @param obj pointer to a slider object
* @param en the type of the slider. See ::lv_slider_type_t * @param mode the mode of the slider. See ::lv_slider_mode_t
*/ */
static inline void lv_slider_set_type(lv_obj_t * obj, lv_slider_type_t type) static inline void lv_slider_set_mode(lv_obj_t * obj, lv_slider_mode_t mode)
{ {
lv_bar_set_type(obj, (lv_bar_type_t)type); lv_bar_set_mode(obj, (lv_bar_mode_t)mode);
} }
/*===================== /*=====================
@@ -163,16 +163,16 @@ static inline int16_t lv_slider_get_max_value(const lv_obj_t * obj)
bool lv_slider_is_dragged(const lv_obj_t * obj); bool lv_slider_is_dragged(const lv_obj_t * obj);
/** /**
* Get the type of the slider. * Get the mode of the slider.
* @param obj pointer to a bar object * @param obj pointer to a bar object
* @return see ::lv_slider_type_t * @return see ::lv_slider_mode_t
*/ */
static inline lv_slider_type_t lv_slider_get_type(lv_obj_t * slider) static inline lv_slider_mode_t lv_slider_get_mode(lv_obj_t * slider)
{ {
lv_bar_type_t type = lv_bar_get_type(slider); lv_bar_mode_t mode = lv_bar_get_mode(slider);
if(type == LV_BAR_TYPE_SYMMETRICAL) return LV_SLIDER_TYPE_SYMMETRICAL; if(mode == LV_BAR_MODE_SYMMETRICAL) return LV_SLIDER_MODE_SYMMETRICAL;
else if(type == LV_BAR_TYPE_RANGE) return LV_SLIDER_TYPE_RANGE; else if(mode == LV_BAR_MODE_RANGE) return LV_SLIDER_MODE_RANGE;
else return LV_SLIDER_TYPE_NORMAL; else return LV_SLIDER_MODE_NORMAL;
} }
/********************** /**********************

View File

@@ -105,8 +105,6 @@ static void lv_switch_event(lv_obj_t * obj, lv_event_t e)
knob_size += 2; /*For rounding error*/ knob_size += 2; /*For rounding error*/
knob_size += lv_obj_calculate_ext_draw_size(obj, LV_PART_KNOB); knob_size += lv_obj_calculate_ext_draw_size(obj, LV_PART_KNOB);
// knob_size = (knob_size - lv_obj_get_height(obj)) / 2;
lv_coord_t * s = lv_event_get_param(); lv_coord_t * s = lv_event_get_param();
*s = LV_MAX(*s, knob_size); *s = LV_MAX(*s, knob_size);
*s = LV_MAX(*s, lv_obj_calculate_ext_draw_size(obj, LV_PART_INDICATOR)); *s = LV_MAX(*s, lv_obj_calculate_ext_draw_size(obj, LV_PART_INDICATOR));

View File

@@ -1055,17 +1055,14 @@ static void lv_textarea_event(lv_obj_t * obj, lv_event_t e)
else if(e == LV_EVENT_FOCUSED) { else if(e == LV_EVENT_FOCUSED) {
start_cursor_blink(obj); start_cursor_blink(obj);
} }
else if(e == LV_EVENT_COORD_CHANGED) { else if(e == LV_EVENT_SIZE_CHANGED) {
/*Set the label width according to the text area width*/ /*Set the label width according to the text area width*/
if(ta->label) { if(ta->label) {
void * param = lv_event_get_param(); lv_obj_set_width(ta->label, lv_obj_get_width_fit(obj));
if(lv_obj_get_width(obj) != lv_area_get_width(param) || lv_obj_get_height(obj) != lv_area_get_height(param)) { lv_obj_set_pos(ta->label, 0, 0);
lv_obj_set_width(ta->label, lv_obj_get_width_fit(obj)); lv_label_set_text(ta->label, NULL); /*Refresh the label*/
lv_obj_set_pos(ta->label, 0, 0);
lv_label_set_text(ta->label, NULL); /*Refresh the label*/
refr_cursor_area(obj); refr_cursor_area(obj);
}
} }
} }
else if(e == LV_EVENT_KEY) { else if(e == LV_EVENT_KEY) {