mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
移动文件夹
This commit is contained in:
536
software/Power_Pico/Middlewares/LVGL/src/layouts/flex/lv_flex.c
Normal file
536
software/Power_Pico/Middlewares/LVGL/src/layouts/flex/lv_flex.c
Normal file
@@ -0,0 +1,536 @@
|
||||
/**
|
||||
* @file lv_flex.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_flex.h"
|
||||
#include "../lv_layout.h"
|
||||
#include "../../core/lv_obj_private.h"
|
||||
|
||||
#if LV_USE_FLEX
|
||||
|
||||
#include "../../core/lv_global.h"
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define layout_list_def LV_GLOBAL_DEFAULT()->layout_list
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef struct {
|
||||
lv_flex_align_t main_place;
|
||||
lv_flex_align_t cross_place;
|
||||
lv_flex_align_t track_place;
|
||||
uint8_t row : 1;
|
||||
uint8_t wrap : 1;
|
||||
uint8_t rev : 1;
|
||||
} flex_t;
|
||||
|
||||
typedef struct {
|
||||
lv_obj_t * item;
|
||||
int32_t min_size;
|
||||
int32_t max_size;
|
||||
int32_t final_size;
|
||||
uint32_t grow_value;
|
||||
uint32_t clamped : 1;
|
||||
} grow_dsc_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t track_cross_size;
|
||||
int32_t track_main_size; /*For all items*/
|
||||
int32_t track_fix_main_size; /*For non grow items*/
|
||||
uint32_t item_cnt;
|
||||
grow_dsc_t * grow_dsc;
|
||||
uint32_t grow_item_cnt;
|
||||
uint32_t grow_dsc_calc : 1;
|
||||
} track_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void flex_update(lv_obj_t * cont, void * user_data);
|
||||
static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id, int32_t max_main_size,
|
||||
int32_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, int32_t abs_x,
|
||||
int32_t abs_y, int32_t max_main_size, int32_t item_gap, track_t * t);
|
||||
static void place_content(lv_flex_align_t place, int32_t max_size, int32_t content_size, int32_t item_cnt,
|
||||
int32_t * start_pos, int32_t * gap);
|
||||
static lv_obj_t * get_next_item(lv_obj_t * cont, bool rev, int32_t * item_id);
|
||||
static int32_t lv_obj_get_width_with_margin(const lv_obj_t * obj);
|
||||
static int32_t lv_obj_get_height_with_margin(const lv_obj_t * obj);
|
||||
|
||||
/**********************
|
||||
* GLOBAL VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
#if LV_USE_LOG && LV_LOG_TRACE_LAYOUT
|
||||
#define LV_TRACE_LAYOUT(...) LV_LOG_TRACE(__VA_ARGS__)
|
||||
#else
|
||||
#define LV_TRACE_LAYOUT(...)
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
void lv_flex_init(void)
|
||||
{
|
||||
layout_list_def[LV_LAYOUT_FLEX].cb = flex_update;
|
||||
layout_list_def[LV_LAYOUT_FLEX].user_data = NULL;
|
||||
}
|
||||
|
||||
void lv_obj_set_flex_flow(lv_obj_t * obj, lv_flex_flow_t flow)
|
||||
{
|
||||
lv_obj_set_style_flex_flow(obj, flow, 0);
|
||||
lv_obj_set_style_layout(obj, LV_LAYOUT_FLEX, 0);
|
||||
}
|
||||
|
||||
void lv_obj_set_flex_align(lv_obj_t * obj, lv_flex_align_t main_place, lv_flex_align_t cross_place,
|
||||
lv_flex_align_t track_place)
|
||||
{
|
||||
lv_obj_set_style_flex_main_place(obj, main_place, 0);
|
||||
lv_obj_set_style_flex_cross_place(obj, cross_place, 0);
|
||||
lv_obj_set_style_flex_track_place(obj, track_place, 0);
|
||||
lv_obj_set_style_layout(obj, LV_LAYOUT_FLEX, 0);
|
||||
}
|
||||
|
||||
void lv_obj_set_flex_grow(lv_obj_t * obj, uint8_t grow)
|
||||
{
|
||||
lv_obj_set_style_flex_grow(obj, grow, 0);
|
||||
lv_obj_mark_layout_as_dirty(lv_obj_get_parent(obj));
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static void flex_update(lv_obj_t * cont, void * user_data)
|
||||
{
|
||||
LV_LOG_INFO("update %p container", (void *)cont);
|
||||
LV_UNUSED(user_data);
|
||||
|
||||
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_style_base_dir(cont, LV_PART_MAIN) == LV_BASE_DIR_RTL;
|
||||
int32_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);
|
||||
int32_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);
|
||||
int32_t max_main_size = (f.row ? lv_obj_get_content_width(cont) : lv_obj_get_content_height(cont));
|
||||
int32_t abs_y = cont->coords.y1 + lv_obj_get_style_space_top(cont,
|
||||
LV_PART_MAIN) - lv_obj_get_scroll_y(cont);
|
||||
int32_t abs_x = cont->coords.x1 + lv_obj_get_style_space_left(cont,
|
||||
LV_PART_MAIN) - lv_obj_get_scroll_x(cont);
|
||||
|
||||
lv_flex_align_t track_cross_place = f.track_place;
|
||||
int32_t * cross_pos = (f.row ? &abs_y : &abs_x);
|
||||
|
||||
int32_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN);
|
||||
int32_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN);
|
||||
|
||||
/*Content sized objects should squeeze the gap between the children, therefore any alignment will look like `START`*/
|
||||
if((f.row && h_set == LV_SIZE_CONTENT && cont->h_layout == 0) ||
|
||||
(!f.row && w_set == LV_SIZE_CONTENT && cont->w_layout == 0)) {
|
||||
track_cross_place = LV_FLEX_ALIGN_START;
|
||||
}
|
||||
|
||||
if(rtl && !f.row) {
|
||||
if(track_cross_place == LV_FLEX_ALIGN_START) track_cross_place = LV_FLEX_ALIGN_END;
|
||||
else if(track_cross_place == LV_FLEX_ALIGN_END) track_cross_place = LV_FLEX_ALIGN_START;
|
||||
}
|
||||
|
||||
int32_t total_track_cross_size = 0;
|
||||
int32_t gap = 0;
|
||||
uint32_t track_cnt = 0;
|
||||
int32_t track_first_item;
|
||||
int32_t next_track_first_item;
|
||||
|
||||
if(track_cross_place != LV_FLEX_ALIGN_START) {
|
||||
track_first_item = f.rev ? cont->spec_attr->child_cnt - 1 : 0;
|
||||
track_t t;
|
||||
while(track_first_item < (int32_t)cont->spec_attr->child_cnt && track_first_item >= 0) {
|
||||
/*Search the first item of the next row*/
|
||||
t.grow_dsc_calc = 0;
|
||||
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;
|
||||
track_cnt++;
|
||||
track_first_item = next_track_first_item;
|
||||
}
|
||||
|
||||
if(track_cnt) total_track_cross_size -= track_gap; /*No gap after the last track*/
|
||||
|
||||
/*Place the tracks to get the start position*/
|
||||
int32_t max_cross_size = (f.row ? lv_obj_get_content_height(cont) : lv_obj_get_content_width(cont));
|
||||
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;
|
||||
|
||||
if(rtl && !f.row) {
|
||||
*cross_pos += total_track_cross_size;
|
||||
}
|
||||
|
||||
while(track_first_item < (int32_t)cont->spec_attr->child_cnt && track_first_item >= 0) {
|
||||
track_t t;
|
||||
t.grow_dsc_calc = 1;
|
||||
/*Search the first item of the next row*/
|
||||
next_track_first_item = find_track_end(cont, &f, track_first_item, max_main_size, item_gap, &t);
|
||||
|
||||
if(rtl && !f.row) {
|
||||
*cross_pos -= t.track_cross_size;
|
||||
}
|
||||
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;
|
||||
lv_free(t.grow_dsc);
|
||||
t.grow_dsc = NULL;
|
||||
if(rtl && !f.row) {
|
||||
*cross_pos -= gap + track_gap;
|
||||
}
|
||||
else {
|
||||
*cross_pos += t.track_cross_size + gap + track_gap;
|
||||
}
|
||||
}
|
||||
LV_ASSERT_MEM_INTEGRITY();
|
||||
|
||||
if(w_set == LV_SIZE_CONTENT || h_set == LV_SIZE_CONTENT) {
|
||||
lv_obj_refr_size(cont);
|
||||
}
|
||||
|
||||
lv_obj_send_event(cont, LV_EVENT_LAYOUT_CHANGED, NULL);
|
||||
|
||||
LV_TRACE_LAYOUT("finished");
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the last item of a track
|
||||
*/
|
||||
static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id, int32_t max_main_size,
|
||||
int32_t item_gap, track_t * t)
|
||||
{
|
||||
int32_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN);
|
||||
int32_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN);
|
||||
|
||||
/*Can't wrap if the size is auto (i.e. the size depends on the children)*/
|
||||
if(f->wrap && ((f->row && w_set == LV_SIZE_CONTENT) || (!f->row && h_set == LV_SIZE_CONTENT))) {
|
||||
f->wrap = false;
|
||||
}
|
||||
int32_t(*get_main_size)(const lv_obj_t *) = (f->row ? lv_obj_get_width_with_margin : lv_obj_get_height_with_margin);
|
||||
int32_t(*get_cross_size)(const lv_obj_t *) = (!f->row ? lv_obj_get_width_with_margin :
|
||||
lv_obj_get_height_with_margin);
|
||||
|
||||
t->track_main_size = 0;
|
||||
t->track_fix_main_size = 0;
|
||||
t->grow_item_cnt = 0;
|
||||
t->track_cross_size = 0;
|
||||
t->item_cnt = 0;
|
||||
t->grow_dsc = NULL;
|
||||
|
||||
int32_t item_id = item_start_id;
|
||||
|
||||
lv_obj_t * item = lv_obj_get_child(cont, item_id);
|
||||
while(item) {
|
||||
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)) {
|
||||
uint8_t grow_value = lv_obj_get_style_flex_grow(item, LV_PART_MAIN);
|
||||
if(grow_value) {
|
||||
t->grow_item_cnt++;
|
||||
t->track_fix_main_size += item_gap;
|
||||
if(t->grow_dsc_calc) {
|
||||
grow_dsc_t * new_dsc = lv_realloc(t->grow_dsc, sizeof(grow_dsc_t) * (t->grow_item_cnt));
|
||||
LV_ASSERT_MALLOC(new_dsc);
|
||||
if(new_dsc == NULL) return item_id;
|
||||
|
||||
new_dsc[t->grow_item_cnt - 1].item = item;
|
||||
new_dsc[t->grow_item_cnt - 1].min_size = f->row ? lv_obj_get_style_min_width(item, LV_PART_MAIN)
|
||||
: lv_obj_get_style_min_height(item, LV_PART_MAIN);
|
||||
new_dsc[t->grow_item_cnt - 1].max_size = f->row ? lv_obj_get_style_max_width(item, LV_PART_MAIN)
|
||||
: lv_obj_get_style_max_height(item, LV_PART_MAIN);
|
||||
new_dsc[t->grow_item_cnt - 1].grow_value = grow_value;
|
||||
new_dsc[t->grow_item_cnt - 1].clamped = 0;
|
||||
t->grow_dsc = new_dsc;
|
||||
}
|
||||
}
|
||||
else {
|
||||
int32_t item_size = get_main_size(item);
|
||||
if(f->wrap && t->track_fix_main_size + item_size > max_main_size) break;
|
||||
t->track_fix_main_size += item_size + item_gap;
|
||||
}
|
||||
|
||||
t->track_cross_size = LV_MAX(get_cross_size(item), t->track_cross_size);
|
||||
t->item_cnt++;
|
||||
}
|
||||
|
||||
item_id += f->rev ? -1 : +1;
|
||||
if(item_id < 0) break;
|
||||
item = lv_obj_get_child(cont, item_id);
|
||||
}
|
||||
|
||||
if(t->track_fix_main_size > 0) t->track_fix_main_size -= item_gap; /*There is no gap after the last item*/
|
||||
|
||||
/*If there is at least one "grow item" the track takes the full space*/
|
||||
t->track_main_size = t->grow_item_cnt ? max_main_size : t->track_fix_main_size;
|
||||
|
||||
/*Have at least one item in a row*/
|
||||
if(item && item_id == item_start_id) {
|
||||
item = cont->spec_attr->children[item_id];
|
||||
get_next_item(cont, f->rev, &item_id);
|
||||
if(item) {
|
||||
t->track_cross_size = get_cross_size(item);
|
||||
t->track_main_size = get_main_size(item);
|
||||
t->item_cnt = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return item_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Position the children in the same track
|
||||
*/
|
||||
static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, int32_t item_last_id, int32_t abs_x,
|
||||
int32_t abs_y, int32_t max_main_size, int32_t item_gap, track_t * t)
|
||||
{
|
||||
void (*area_set_main_size)(lv_area_t *, int32_t) = (f->row ? lv_area_set_width : lv_area_set_height);
|
||||
int32_t (*area_get_main_size)(const lv_area_t *) = (f->row ? lv_area_get_width : lv_area_get_height);
|
||||
int32_t (*area_get_cross_size)(const lv_area_t *) = (!f->row ? lv_area_get_width : lv_area_get_height);
|
||||
|
||||
typedef int32_t (*margin_func_t)(const lv_obj_t *, uint32_t);
|
||||
margin_func_t get_margin_main_start = (f->row ? lv_obj_get_style_margin_left : lv_obj_get_style_margin_top);
|
||||
margin_func_t get_margin_main_end = (f->row ? lv_obj_get_style_margin_right : lv_obj_get_style_margin_bottom);
|
||||
margin_func_t get_margin_cross_start = (!f->row ? lv_obj_get_style_margin_left : lv_obj_get_style_margin_top);
|
||||
margin_func_t get_margin_cross_end = (!f->row ? lv_obj_get_style_margin_right : lv_obj_get_style_margin_bottom);
|
||||
|
||||
/*Calculate the size of grow items first*/
|
||||
uint32_t i;
|
||||
bool grow_reiterate = true;
|
||||
while(grow_reiterate && t->grow_item_cnt) {
|
||||
grow_reiterate = false;
|
||||
int32_t grow_value_sum = 0;
|
||||
int32_t grow_max_size = t->track_main_size - t->track_fix_main_size;
|
||||
for(i = 0; i < t->grow_item_cnt; i++) {
|
||||
if(t->grow_dsc[i].clamped == 0) {
|
||||
grow_value_sum += t->grow_dsc[i].grow_value;
|
||||
}
|
||||
else {
|
||||
grow_max_size -= t->grow_dsc[i].final_size;
|
||||
}
|
||||
}
|
||||
int32_t grow_unit;
|
||||
|
||||
for(i = 0; i < t->grow_item_cnt; i++) {
|
||||
if(t->grow_dsc[i].clamped == 0) {
|
||||
LV_ASSERT(grow_value_sum != 0);
|
||||
grow_unit = grow_max_size / grow_value_sum;
|
||||
int32_t size = grow_unit * t->grow_dsc[i].grow_value;
|
||||
int32_t size_clamp = LV_CLAMP(t->grow_dsc[i].min_size, size, t->grow_dsc[i].max_size);
|
||||
|
||||
if(size_clamp != size) {
|
||||
t->grow_dsc[i].clamped = 1;
|
||||
grow_reiterate = true;
|
||||
}
|
||||
t->grow_dsc[i].final_size = size_clamp;
|
||||
grow_value_sum -= t->grow_dsc[i].grow_value;
|
||||
grow_max_size -= t->grow_dsc[i].final_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool rtl = lv_obj_get_style_base_dir(cont, LV_PART_MAIN) == LV_BASE_DIR_RTL;
|
||||
|
||||
int32_t main_pos = 0;
|
||||
|
||||
int32_t place_gap = 0;
|
||||
place_content(f->main_place, max_main_size, t->track_main_size, t->item_cnt, &main_pos, &place_gap);
|
||||
if(f->row && rtl) main_pos += lv_obj_get_content_width(cont);
|
||||
|
||||
lv_obj_t * item = lv_obj_get_child(cont, item_first_id);
|
||||
/*Reposition the children*/
|
||||
while(item && item_first_id != item_last_id) {
|
||||
if(lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) {
|
||||
item = get_next_item(cont, f->rev, &item_first_id);
|
||||
continue;
|
||||
}
|
||||
int32_t grow_size = lv_obj_get_style_flex_grow(item, LV_PART_MAIN);
|
||||
if(grow_size) {
|
||||
int32_t s = 0;
|
||||
for(i = 0; i < t->grow_item_cnt; i++) {
|
||||
if(t->grow_dsc[i].item == item) {
|
||||
s = t->grow_dsc[i].final_size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(f->row) {
|
||||
item->w_layout = 1;
|
||||
item->h_layout = 0;
|
||||
}
|
||||
else {
|
||||
item->h_layout = 1;
|
||||
item->w_layout = 0;
|
||||
}
|
||||
|
||||
if(s != area_get_main_size(&item->coords)) {
|
||||
lv_obj_invalidate(item);
|
||||
|
||||
lv_area_t old_coords;
|
||||
lv_area_copy(&old_coords, &item->coords);
|
||||
area_set_main_size(&item->coords, s);
|
||||
lv_obj_send_event(item, LV_EVENT_SIZE_CHANGED, &old_coords);
|
||||
lv_obj_send_event(lv_obj_get_parent(item), LV_EVENT_CHILD_CHANGED, item);
|
||||
lv_obj_invalidate(item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
item->w_layout = 0;
|
||||
item->h_layout = 0;
|
||||
}
|
||||
|
||||
int32_t cross_pos = 0;
|
||||
switch(f->cross_place) {
|
||||
case LV_FLEX_ALIGN_CENTER:
|
||||
/*Round up the cross size to avoid rounding error when dividing by 2
|
||||
*The issue comes up e,g, with column direction with center cross direction if an element's width changes*/
|
||||
cross_pos = (((t->track_cross_size + 1) & (~1)) - area_get_cross_size(&item->coords)) / 2;
|
||||
cross_pos += (get_margin_cross_start(item, LV_PART_MAIN) - get_margin_cross_end(item, LV_PART_MAIN)) / 2;
|
||||
break;
|
||||
case LV_FLEX_ALIGN_END:
|
||||
cross_pos = t->track_cross_size - area_get_cross_size(&item->coords);
|
||||
cross_pos -= get_margin_cross_end(item, LV_PART_MAIN);
|
||||
break;
|
||||
default:
|
||||
cross_pos += get_margin_cross_start(item, LV_PART_MAIN);
|
||||
break;
|
||||
}
|
||||
|
||||
if(f->row && rtl) main_pos -= area_get_main_size(&item->coords);
|
||||
|
||||
/*Handle percentage value of translate*/
|
||||
int32_t tr_x = lv_obj_get_style_translate_x(item, LV_PART_MAIN);
|
||||
int32_t tr_y = lv_obj_get_style_translate_y(item, LV_PART_MAIN);
|
||||
int32_t w = lv_obj_get_width(item);
|
||||
int32_t h = lv_obj_get_height(item);
|
||||
if(LV_COORD_IS_PCT(tr_x)) tr_x = (w * LV_COORD_GET_PCT(tr_x)) / 100;
|
||||
if(LV_COORD_IS_PCT(tr_y)) tr_y = (h * LV_COORD_GET_PCT(tr_y)) / 100;
|
||||
|
||||
int32_t diff_x = abs_x - item->coords.x1 + tr_x;
|
||||
int32_t diff_y = abs_y - item->coords.y1 + tr_y;
|
||||
diff_x += f->row ? main_pos + get_margin_main_start(item, LV_PART_MAIN) : cross_pos;
|
||||
diff_y += f->row ? cross_pos : main_pos + get_margin_main_start(item, LV_PART_MAIN);
|
||||
|
||||
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, false);
|
||||
}
|
||||
|
||||
if(!(f->row && rtl)) main_pos += area_get_main_size(&item->coords) + item_gap + place_gap
|
||||
+ get_margin_main_start(item, LV_PART_MAIN)
|
||||
+ get_margin_main_end(item, LV_PART_MAIN);
|
||||
else main_pos -= item_gap + place_gap;
|
||||
|
||||
item = get_next_item(cont, f->rev, &item_first_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell a start coordinate and gap for a placement type.
|
||||
*/
|
||||
static void place_content(lv_flex_align_t place, int32_t max_size, int32_t content_size, int32_t item_cnt,
|
||||
int32_t * start_pos, int32_t * gap)
|
||||
{
|
||||
if(item_cnt <= 1) {
|
||||
switch(place) {
|
||||
case LV_FLEX_ALIGN_SPACE_AROUND:
|
||||
case LV_FLEX_ALIGN_SPACE_EVENLY:
|
||||
place = LV_FLEX_ALIGN_CENTER;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(place) {
|
||||
case LV_FLEX_ALIGN_CENTER:
|
||||
*gap = 0;
|
||||
*start_pos += (max_size - content_size) / 2;
|
||||
break;
|
||||
case LV_FLEX_ALIGN_END:
|
||||
*gap = 0;
|
||||
*start_pos += max_size - content_size;
|
||||
break;
|
||||
case LV_FLEX_ALIGN_SPACE_BETWEEN:
|
||||
if(item_cnt > 1) *gap = (int32_t)(max_size - content_size) / (int32_t)(item_cnt - 1);
|
||||
break;
|
||||
case LV_FLEX_ALIGN_SPACE_AROUND:
|
||||
*gap += (int32_t)(max_size - content_size) / (int32_t)(item_cnt);
|
||||
*start_pos += *gap / 2;
|
||||
break;
|
||||
case LV_FLEX_ALIGN_SPACE_EVENLY:
|
||||
*gap = (int32_t)(max_size - content_size) / (int32_t)(item_cnt + 1);
|
||||
*start_pos += *gap;
|
||||
break;
|
||||
default:
|
||||
*gap = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static lv_obj_t * get_next_item(lv_obj_t * cont, bool rev, int32_t * item_id)
|
||||
{
|
||||
if(rev) {
|
||||
(*item_id)--;
|
||||
if(*item_id >= 0) return cont->spec_attr->children[*item_id];
|
||||
else return NULL;
|
||||
}
|
||||
else {
|
||||
(*item_id)++;
|
||||
if((*item_id) < (int32_t)cont->spec_attr->child_cnt) return cont->spec_attr->children[*item_id];
|
||||
else return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t lv_obj_get_width_with_margin(const lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_margin_left(obj, LV_PART_MAIN)
|
||||
+ lv_obj_get_width(obj)
|
||||
+ lv_obj_get_style_margin_right(obj, LV_PART_MAIN);
|
||||
}
|
||||
|
||||
static int32_t lv_obj_get_height_with_margin(const lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_margin_top(obj, LV_PART_MAIN)
|
||||
+ lv_obj_get_height(obj)
|
||||
+ lv_obj_get_style_margin_bottom(obj, LV_PART_MAIN);
|
||||
}
|
||||
|
||||
#endif /*LV_USE_FLEX*/
|
||||
102
software/Power_Pico/Middlewares/LVGL/src/layouts/flex/lv_flex.h
Normal file
102
software/Power_Pico/Middlewares/LVGL/src/layouts/flex/lv_flex.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* @file lv_flex.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_FLEX_H
|
||||
#define LV_FLEX_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../../lv_conf_internal.h"
|
||||
#include "../../misc/lv_area.h"
|
||||
|
||||
#if LV_USE_FLEX
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
#define LV_FLEX_COLUMN (1 << 0)
|
||||
#define LV_FLEX_WRAP (1 << 2)
|
||||
#define LV_FLEX_REVERSE (1 << 3)
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/*Can't include lv_obj.h because it includes this header file*/
|
||||
|
||||
typedef enum {
|
||||
LV_FLEX_ALIGN_START,
|
||||
LV_FLEX_ALIGN_END,
|
||||
LV_FLEX_ALIGN_CENTER,
|
||||
LV_FLEX_ALIGN_SPACE_EVENLY,
|
||||
LV_FLEX_ALIGN_SPACE_AROUND,
|
||||
LV_FLEX_ALIGN_SPACE_BETWEEN,
|
||||
} lv_flex_align_t;
|
||||
|
||||
typedef enum {
|
||||
LV_FLEX_FLOW_ROW = 0x00,
|
||||
LV_FLEX_FLOW_COLUMN = LV_FLEX_COLUMN,
|
||||
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_WRAP_REVERSE = LV_FLEX_FLOW_ROW | LV_FLEX_WRAP | LV_FLEX_REVERSE,
|
||||
LV_FLEX_FLOW_COLUMN_WRAP = LV_FLEX_FLOW_COLUMN | LV_FLEX_WRAP,
|
||||
LV_FLEX_FLOW_COLUMN_REVERSE = LV_FLEX_FLOW_COLUMN | LV_FLEX_REVERSE,
|
||||
LV_FLEX_FLOW_COLUMN_WRAP_REVERSE = LV_FLEX_FLOW_COLUMN | LV_FLEX_WRAP | LV_FLEX_REVERSE,
|
||||
} lv_flex_flow_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize a flex layout to default values
|
||||
*/
|
||||
void lv_flex_init(void);
|
||||
|
||||
/**
|
||||
* Set how the item should flow
|
||||
* @param obj pointer to an object. The parent must have flex layout else nothing will happen.
|
||||
* @param flow an element of `lv_flex_flow_t`.
|
||||
*/
|
||||
void lv_obj_set_flex_flow(lv_obj_t * obj, lv_flex_flow_t flow);
|
||||
|
||||
/**
|
||||
* Set how to place (where to align) the items and tracks
|
||||
* @param obj pointer to an object. The parent must have flex layout else nothing will happen.
|
||||
* @param main_place where to place the items on main axis (in their track). Any value of `lv_flex_align_t`.
|
||||
* @param cross_place where to place the item in their track on the cross axis. `LV_FLEX_ALIGN_START/END/CENTER`
|
||||
* @param track_cross_place where to place the tracks in the cross direction. Any value of `lv_flex_align_t`.
|
||||
*/
|
||||
void lv_obj_set_flex_align(lv_obj_t * obj, lv_flex_align_t main_place, lv_flex_align_t cross_place,
|
||||
lv_flex_align_t track_cross_place);
|
||||
|
||||
/**
|
||||
* 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 grow a value to set how much free space to take proportionally to other growing items.
|
||||
*/
|
||||
void lv_obj_set_flex_grow(lv_obj_t * obj, uint8_t grow);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*LV_USE_FLEX*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_FLEX_H*/
|
||||
665
software/Power_Pico/Middlewares/LVGL/src/layouts/grid/lv_grid.c
Normal file
665
software/Power_Pico/Middlewares/LVGL/src/layouts/grid/lv_grid.c
Normal file
@@ -0,0 +1,665 @@
|
||||
/**
|
||||
* @file lv_grid.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_grid.h"
|
||||
|
||||
#if LV_USE_GRID
|
||||
|
||||
#include "../../stdlib/lv_string.h"
|
||||
#include "../lv_layout.h"
|
||||
#include "../../core/lv_obj_private.h"
|
||||
#include "../../core/lv_global.h"
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define layout_list_def LV_GLOBAL_DEFAULT()->layout_list
|
||||
|
||||
/**
|
||||
* Some helper defines
|
||||
*/
|
||||
#define IS_FR(x) (x >= LV_COORD_MAX - 100)
|
||||
#define IS_CONTENT(x) (x == LV_COORD_MAX - 101)
|
||||
#define GET_FR(x) (x - (LV_COORD_MAX - 100))
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef struct {
|
||||
uint32_t col;
|
||||
uint32_t row;
|
||||
lv_point_t grid_abs;
|
||||
} item_repos_hint_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t * x;
|
||||
int32_t * y;
|
||||
int32_t * w;
|
||||
int32_t * h;
|
||||
uint32_t col_num;
|
||||
uint32_t row_num;
|
||||
int32_t grid_w;
|
||||
int32_t grid_h;
|
||||
} lv_grid_calc_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void grid_update(lv_obj_t * cont, void * user_data);
|
||||
static void calc(lv_obj_t * obj, 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_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 int32_t grid_align(int32_t cont_size, bool auto_size, lv_grid_align_t align, int32_t gap,
|
||||
uint32_t track_num,
|
||||
int32_t * size_array, int32_t * pos_array, bool reverse);
|
||||
static uint32_t count_tracks(const int32_t * templ);
|
||||
|
||||
static inline const int32_t * get_col_dsc(lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_grid_column_dsc_array(obj, 0);
|
||||
}
|
||||
static inline const int32_t * get_row_dsc(lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_grid_row_dsc_array(obj, 0);
|
||||
}
|
||||
static inline int32_t get_col_pos(lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_grid_cell_column_pos(obj, 0);
|
||||
}
|
||||
static inline int32_t get_row_pos(lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_grid_cell_row_pos(obj, 0);
|
||||
}
|
||||
static inline int32_t get_col_span(lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_grid_cell_column_span(obj, 0);
|
||||
}
|
||||
static inline int32_t get_row_span(lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_grid_cell_row_span(obj, 0);
|
||||
}
|
||||
static inline lv_grid_align_t get_cell_col_align(lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_grid_cell_x_align(obj, 0);
|
||||
}
|
||||
static inline lv_grid_align_t get_cell_row_align(lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_grid_cell_y_align(obj, 0);
|
||||
}
|
||||
static inline lv_grid_align_t get_grid_col_align(lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_grid_column_align(obj, 0);
|
||||
}
|
||||
static inline lv_grid_align_t get_grid_row_align(lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_grid_row_align(obj, 0);
|
||||
}
|
||||
static inline int32_t get_margin_hor(lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_margin_left(obj, LV_PART_MAIN)
|
||||
+ lv_obj_get_style_margin_right(obj, LV_PART_MAIN);
|
||||
}
|
||||
static inline int32_t get_margin_ver(lv_obj_t * obj)
|
||||
{
|
||||
return lv_obj_get_style_margin_top(obj, LV_PART_MAIN)
|
||||
+ lv_obj_get_style_margin_bottom(obj, LV_PART_MAIN);
|
||||
}
|
||||
|
||||
static inline int32_t div_round_closest(int32_t dividend, int32_t divisor)
|
||||
{
|
||||
return (dividend + divisor / 2) / divisor;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* GLOBAL VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
#if LV_USE_LOG && LV_LOG_TRACE_LAYOUT
|
||||
#define LV_TRACE_LAYOUT(...) LV_LOG_TRACE(__VA_ARGS__)
|
||||
#else
|
||||
#define LV_TRACE_LAYOUT(...)
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
void lv_grid_init(void)
|
||||
{
|
||||
layout_list_def[LV_LAYOUT_GRID].cb = grid_update;
|
||||
layout_list_def[LV_LAYOUT_GRID].user_data = NULL;
|
||||
}
|
||||
|
||||
void lv_obj_set_grid_dsc_array(lv_obj_t * obj, const int32_t col_dsc[], const int32_t row_dsc[])
|
||||
{
|
||||
lv_obj_set_style_grid_column_dsc_array(obj, col_dsc, 0);
|
||||
lv_obj_set_style_grid_row_dsc_array(obj, row_dsc, 0);
|
||||
lv_obj_set_style_layout(obj, LV_LAYOUT_GRID, 0);
|
||||
}
|
||||
|
||||
void lv_obj_set_grid_align(lv_obj_t * obj, lv_grid_align_t column_align, lv_grid_align_t row_align)
|
||||
{
|
||||
lv_obj_set_style_grid_column_align(obj, column_align, 0);
|
||||
lv_obj_set_style_grid_row_align(obj, row_align, 0);
|
||||
|
||||
}
|
||||
|
||||
void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_align_t x_align, int32_t col_pos, int32_t col_span,
|
||||
lv_grid_align_t y_align, int32_t row_pos, int32_t row_span)
|
||||
|
||||
{
|
||||
lv_obj_set_style_grid_cell_column_pos(obj, col_pos, 0);
|
||||
lv_obj_set_style_grid_cell_row_pos(obj, row_pos, 0);
|
||||
lv_obj_set_style_grid_cell_x_align(obj, x_align, 0);
|
||||
lv_obj_set_style_grid_cell_column_span(obj, col_span, 0);
|
||||
lv_obj_set_style_grid_cell_row_span(obj, row_span, 0);
|
||||
lv_obj_set_style_grid_cell_y_align(obj, y_align, 0);
|
||||
|
||||
lv_obj_mark_layout_as_dirty(lv_obj_get_parent(obj));
|
||||
}
|
||||
|
||||
int32_t lv_grid_fr(uint8_t x)
|
||||
{
|
||||
return LV_GRID_FR(x);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static void grid_update(lv_obj_t * cont, void * user_data)
|
||||
{
|
||||
LV_LOG_INFO("update %p container", (void *)cont);
|
||||
LV_UNUSED(user_data);
|
||||
|
||||
// const int32_t * col_templ = get_col_dsc(cont);
|
||||
// const int32_t * row_templ = get_row_dsc(cont);
|
||||
// if(col_templ == NULL || row_templ == NULL) return;
|
||||
|
||||
lv_grid_calc_t c;
|
||||
calc(cont, &c);
|
||||
|
||||
item_repos_hint_t hint;
|
||||
lv_memzero(&hint, sizeof(hint));
|
||||
|
||||
/*Calculate the grids absolute x and y coordinates.
|
||||
*It will be used as helper during item repositioning to avoid calculating this value for every children*/
|
||||
int32_t pad_left = lv_obj_get_style_space_left(cont, LV_PART_MAIN);
|
||||
int32_t pad_top = lv_obj_get_style_space_top(cont, LV_PART_MAIN);
|
||||
hint.grid_abs.x = pad_left + cont->coords.x1 - lv_obj_get_scroll_x(cont);
|
||||
hint.grid_abs.y = pad_top + cont->coords.y1 - lv_obj_get_scroll_y(cont);
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; i < cont->spec_attr->child_cnt; i++) {
|
||||
lv_obj_t * item = cont->spec_attr->children[i];
|
||||
item_repos(item, &c, &hint);
|
||||
}
|
||||
calc_free(&c);
|
||||
|
||||
int32_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN);
|
||||
int32_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_obj_send_event(cont, LV_EVENT_LAYOUT_CHANGED, NULL);
|
||||
|
||||
LV_TRACE_LAYOUT("finished");
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the grid cells coordinates
|
||||
* @param cont an object that has a grid
|
||||
* @param calc store the calculated cells sizes here
|
||||
* @note `lv_grid_calc_free(calc_out)` needs to be called when `calc_out` is not needed anymore
|
||||
*/
|
||||
static void calc(lv_obj_t * cont, lv_grid_calc_t * calc_out)
|
||||
{
|
||||
if(lv_obj_get_child(cont, 0) == NULL) {
|
||||
lv_memzero(calc_out, sizeof(lv_grid_calc_t));
|
||||
return;
|
||||
}
|
||||
|
||||
calc_rows(cont, calc_out);
|
||||
calc_cols(cont, calc_out);
|
||||
|
||||
int32_t col_gap = lv_obj_get_style_pad_column(cont, LV_PART_MAIN);
|
||||
int32_t row_gap = lv_obj_get_style_pad_row(cont, LV_PART_MAIN);
|
||||
|
||||
bool rev = lv_obj_get_style_base_dir(cont, LV_PART_MAIN) == LV_BASE_DIR_RTL;
|
||||
|
||||
int32_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN);
|
||||
int32_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN);
|
||||
bool auto_w = w_set == LV_SIZE_CONTENT && !cont->w_layout;
|
||||
int32_t cont_w = lv_obj_get_content_width(cont);
|
||||
calc_out->grid_w = grid_align(cont_w, auto_w, get_grid_col_align(cont), col_gap, calc_out->col_num, calc_out->w,
|
||||
calc_out->x, rev);
|
||||
|
||||
bool auto_h = h_set == LV_SIZE_CONTENT && !cont->h_layout;
|
||||
int32_t cont_h = lv_obj_get_content_height(cont);
|
||||
calc_out->grid_h = grid_align(cont_h, auto_h, get_grid_row_align(cont), row_gap, calc_out->row_num, calc_out->h,
|
||||
calc_out->y, false);
|
||||
|
||||
LV_ASSERT_MEM_INTEGRITY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the a grid calculation's data
|
||||
* @param calc pointer to the calculated grid cell coordinates
|
||||
*/
|
||||
static void calc_free(lv_grid_calc_t * calc)
|
||||
{
|
||||
lv_free(calc->x);
|
||||
lv_free(calc->y);
|
||||
lv_free(calc->w);
|
||||
lv_free(calc->h);
|
||||
}
|
||||
|
||||
static void calc_cols(lv_obj_t * cont, lv_grid_calc_t * c)
|
||||
{
|
||||
|
||||
const int32_t * col_templ;
|
||||
col_templ = get_col_dsc(cont);
|
||||
bool subgrid = false;
|
||||
if(col_templ == NULL) {
|
||||
lv_obj_t * parent = lv_obj_get_parent(cont);
|
||||
col_templ = get_col_dsc(parent);
|
||||
if(col_templ == NULL) {
|
||||
LV_LOG_WARN("No col descriptor found even on the parent");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t pos = get_col_pos(cont);
|
||||
int32_t span = get_col_span(cont);
|
||||
|
||||
int32_t * col_templ_sub = lv_malloc(sizeof(int32_t) * (span + 1));
|
||||
lv_memcpy(col_templ_sub, &col_templ[pos], sizeof(int32_t) * span);
|
||||
col_templ_sub[span] = LV_GRID_TEMPLATE_LAST;
|
||||
col_templ = col_templ_sub;
|
||||
subgrid = true;
|
||||
}
|
||||
|
||||
int32_t cont_w = lv_obj_get_content_width(cont);
|
||||
|
||||
c->col_num = count_tracks(col_templ);
|
||||
c->x = lv_malloc(sizeof(int32_t) * c->col_num);
|
||||
c->w = lv_malloc(sizeof(int32_t) * c->col_num);
|
||||
|
||||
/*Set sizes for CONTENT cells*/
|
||||
uint32_t i;
|
||||
for(i = 0; i < c->col_num; i++) {
|
||||
int32_t size = LV_COORD_MIN;
|
||||
if(IS_CONTENT(col_templ[i])) {
|
||||
/*Check the size of children of this cell*/
|
||||
uint32_t ci;
|
||||
for(ci = 0; ci < lv_obj_get_child_count(cont); ci++) {
|
||||
lv_obj_t * item = lv_obj_get_child(cont, ci);
|
||||
if(lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) continue;
|
||||
uint32_t col_span = get_col_span(item);
|
||||
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));
|
||||
}
|
||||
if(size >= 0) c->w[i] = size;
|
||||
else c->w[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t col_fr_cnt = 0;
|
||||
int32_t grid_w = 0;
|
||||
|
||||
for(i = 0; i < c->col_num; i++) {
|
||||
int32_t x = col_templ[i];
|
||||
if(IS_FR(x)) {
|
||||
col_fr_cnt += GET_FR(x);
|
||||
}
|
||||
else if(IS_CONTENT(x)) {
|
||||
grid_w += c->w[i];
|
||||
}
|
||||
else {
|
||||
c->w[i] = x;
|
||||
grid_w += x;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t col_gap = lv_obj_get_style_pad_column(cont, LV_PART_MAIN);
|
||||
cont_w -= col_gap * (c->col_num - 1);
|
||||
int32_t free_w = cont_w - grid_w;
|
||||
if(free_w < 0) free_w = 0;
|
||||
|
||||
for(i = 0; i < c->col_num && col_fr_cnt; i++) {
|
||||
int32_t x = col_templ[i];
|
||||
if(IS_FR(x)) {
|
||||
int32_t f = GET_FR(x);
|
||||
c->w[i] = div_round_closest(free_w * f, col_fr_cnt);
|
||||
/*By updating remaining fr and width, we ensure f == col_fr_cnt
|
||||
*in the last loop iteration. That means the last iteration will
|
||||
*not have rounding errors and use all remaining space.*/
|
||||
col_fr_cnt -= f;
|
||||
free_w -= c->w[i];
|
||||
}
|
||||
}
|
||||
|
||||
if(subgrid) {
|
||||
lv_free((void *)col_templ);
|
||||
}
|
||||
}
|
||||
|
||||
static void calc_rows(lv_obj_t * cont, lv_grid_calc_t * c)
|
||||
{
|
||||
const int32_t * row_templ;
|
||||
row_templ = get_row_dsc(cont);
|
||||
bool subgrid = false;
|
||||
if(row_templ == NULL) {
|
||||
lv_obj_t * parent = lv_obj_get_parent(cont);
|
||||
row_templ = get_row_dsc(parent);
|
||||
if(row_templ == NULL) {
|
||||
LV_LOG_WARN("No row descriptor found even on the parent");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t pos = get_row_pos(cont);
|
||||
int32_t span = get_row_span(cont);
|
||||
|
||||
int32_t * row_templ_sub = lv_malloc(sizeof(int32_t) * (span + 1));
|
||||
lv_memcpy(row_templ_sub, &row_templ[pos], sizeof(int32_t) * span);
|
||||
row_templ_sub[span] = LV_GRID_TEMPLATE_LAST;
|
||||
row_templ = row_templ_sub;
|
||||
subgrid = true;
|
||||
}
|
||||
|
||||
c->row_num = count_tracks(row_templ);
|
||||
c->y = lv_malloc(sizeof(int32_t) * c->row_num);
|
||||
c->h = lv_malloc(sizeof(int32_t) * c->row_num);
|
||||
/*Set sizes for CONTENT cells*/
|
||||
uint32_t i;
|
||||
for(i = 0; i < c->row_num; i++) {
|
||||
int32_t size = LV_COORD_MIN;
|
||||
if(IS_CONTENT(row_templ[i])) {
|
||||
/*Check the size of children of this cell*/
|
||||
uint32_t ci;
|
||||
for(ci = 0; ci < lv_obj_get_child_count(cont); ci++) {
|
||||
lv_obj_t * item = lv_obj_get_child(cont, ci);
|
||||
if(lv_obj_has_flag_any(item, LV_OBJ_FLAG_IGNORE_LAYOUT | LV_OBJ_FLAG_HIDDEN | LV_OBJ_FLAG_FLOATING)) continue;
|
||||
uint32_t row_span = get_row_span(item);
|
||||
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));
|
||||
}
|
||||
if(size >= 0) c->h[i] = size;
|
||||
else c->h[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t row_fr_cnt = 0;
|
||||
int32_t grid_h = 0;
|
||||
|
||||
for(i = 0; i < c->row_num; i++) {
|
||||
int32_t x = row_templ[i];
|
||||
if(IS_FR(x)) {
|
||||
row_fr_cnt += GET_FR(x);
|
||||
}
|
||||
else if(IS_CONTENT(x)) {
|
||||
grid_h += c->h[i];
|
||||
}
|
||||
else {
|
||||
c->h[i] = x;
|
||||
grid_h += x;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t row_gap = lv_obj_get_style_pad_row(cont, LV_PART_MAIN);
|
||||
int32_t cont_h = lv_obj_get_content_height(cont) - row_gap * (c->row_num - 1);
|
||||
int32_t free_h = cont_h - grid_h;
|
||||
if(free_h < 0) free_h = 0;
|
||||
|
||||
for(i = 0; i < c->row_num && row_fr_cnt; i++) {
|
||||
int32_t x = row_templ[i];
|
||||
if(IS_FR(x)) {
|
||||
int32_t f = GET_FR(x);
|
||||
c->h[i] = div_round_closest(free_h * f, row_fr_cnt);
|
||||
/*By updating remaining fr and height, we ensure f == row_fr_cnt
|
||||
*in the last loop iteration. That means the last iteration will
|
||||
*not have rounding errors and use all remaining space.*/
|
||||
row_fr_cnt -= f;
|
||||
free_h -= c->h[i];
|
||||
}
|
||||
}
|
||||
|
||||
if(subgrid) {
|
||||
lv_free((void *)row_templ);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reposition a grid item in its cell
|
||||
* @param item a grid item to reposition
|
||||
* @param calc the calculated grid of `cont`
|
||||
* @param child_id_ext helper value if the ID of the child is know (order from the oldest) else -1
|
||||
* @param grid_abs helper value, the absolute position of the grid, NULL if unknown
|
||||
*/
|
||||
static void item_repos(lv_obj_t * item, lv_grid_calc_t * c, item_repos_hint_t * hint)
|
||||
{
|
||||
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_col_span(item);
|
||||
uint32_t row_span = get_row_span(item);
|
||||
if(row_span == 0 || col_span == 0) return;
|
||||
|
||||
uint32_t col_pos = get_col_pos(item);
|
||||
uint32_t row_pos = get_row_pos(item);
|
||||
lv_grid_align_t col_align = get_cell_col_align(item);
|
||||
lv_grid_align_t row_align = get_cell_row_align(item);
|
||||
|
||||
int32_t col_x1 = c->x[col_pos];
|
||||
int32_t col_x2 = c->x[col_pos + col_span - 1] + c->w[col_pos + col_span - 1];
|
||||
int32_t col_w = col_x2 - col_x1;
|
||||
|
||||
int32_t row_y1 = c->y[row_pos];
|
||||
int32_t row_y2 = c->y[row_pos + row_span - 1] + c->h[row_pos + row_span - 1];
|
||||
int32_t row_h = row_y2 - row_y1;
|
||||
|
||||
/*If the item has RTL base dir switch start and end*/
|
||||
if(lv_obj_get_style_base_dir(item, LV_PART_MAIN) == LV_BASE_DIR_RTL) {
|
||||
if(col_align == LV_GRID_ALIGN_START) col_align = LV_GRID_ALIGN_END;
|
||||
else if(col_align == LV_GRID_ALIGN_END) col_align = LV_GRID_ALIGN_START;
|
||||
}
|
||||
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
int32_t item_w = lv_area_get_width(&item->coords);
|
||||
int32_t item_h = lv_area_get_height(&item->coords);
|
||||
|
||||
switch(col_align) {
|
||||
default:
|
||||
case LV_GRID_ALIGN_START:
|
||||
x = c->x[col_pos] + lv_obj_get_style_margin_left(item, LV_PART_MAIN);
|
||||
item->w_layout = 0;
|
||||
break;
|
||||
case LV_GRID_ALIGN_STRETCH:
|
||||
x = c->x[col_pos] + lv_obj_get_style_margin_left(item, LV_PART_MAIN);
|
||||
item_w = col_w - get_margin_hor(item);
|
||||
item->w_layout = 1;
|
||||
break;
|
||||
case LV_GRID_ALIGN_CENTER:
|
||||
x = c->x[col_pos] + (col_w - item_w) / 2 + (lv_obj_get_style_margin_left(item, LV_PART_MAIN) -
|
||||
lv_obj_get_style_margin_right(item, LV_PART_MAIN)) / 2;
|
||||
item->w_layout = 0;
|
||||
break;
|
||||
case LV_GRID_ALIGN_END:
|
||||
x = c->x[col_pos] + col_w - lv_obj_get_width(item) - lv_obj_get_style_margin_right(item, LV_PART_MAIN);
|
||||
item->w_layout = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(row_align) {
|
||||
default:
|
||||
case LV_GRID_ALIGN_START:
|
||||
y = c->y[row_pos] + lv_obj_get_style_margin_top(item, LV_PART_MAIN);
|
||||
item->h_layout = 0;
|
||||
break;
|
||||
case LV_GRID_ALIGN_STRETCH:
|
||||
y = c->y[row_pos] + lv_obj_get_style_margin_top(item, LV_PART_MAIN);
|
||||
item_h = row_h - get_margin_ver(item);
|
||||
item->h_layout = 1;
|
||||
break;
|
||||
case LV_GRID_ALIGN_CENTER:
|
||||
y = c->y[row_pos] + (row_h - item_h) / 2 + (lv_obj_get_style_margin_top(item, LV_PART_MAIN) -
|
||||
lv_obj_get_style_margin_bottom(item, LV_PART_MAIN)) / 2;
|
||||
item->h_layout = 0;
|
||||
break;
|
||||
case LV_GRID_ALIGN_END:
|
||||
y = c->y[row_pos] + row_h - lv_obj_get_height(item) - lv_obj_get_style_margin_bottom(item, LV_PART_MAIN);
|
||||
item->h_layout = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
/*Set a new size if required*/
|
||||
if(lv_obj_get_width(item) != item_w || lv_obj_get_height(item) != item_h) {
|
||||
lv_area_t old_coords;
|
||||
lv_area_copy(&old_coords, &item->coords);
|
||||
lv_obj_invalidate(item);
|
||||
lv_area_set_width(&item->coords, item_w);
|
||||
lv_area_set_height(&item->coords, item_h);
|
||||
lv_obj_invalidate(item);
|
||||
lv_obj_send_event(item, LV_EVENT_SIZE_CHANGED, &old_coords);
|
||||
lv_obj_send_event(lv_obj_get_parent(item), LV_EVENT_CHILD_CHANGED, item);
|
||||
|
||||
}
|
||||
|
||||
/*Handle percentage value of translate*/
|
||||
int32_t tr_x = lv_obj_get_style_translate_x(item, LV_PART_MAIN);
|
||||
int32_t tr_y = lv_obj_get_style_translate_y(item, LV_PART_MAIN);
|
||||
int32_t w = lv_obj_get_width(item);
|
||||
int32_t h = lv_obj_get_height(item);
|
||||
if(LV_COORD_IS_PCT(tr_x)) tr_x = (w * LV_COORD_GET_PCT(tr_x)) / 100;
|
||||
if(LV_COORD_IS_PCT(tr_y)) tr_y = (h * LV_COORD_GET_PCT(tr_y)) / 100;
|
||||
|
||||
x += tr_x;
|
||||
y += tr_y;
|
||||
|
||||
int32_t diff_x = hint->grid_abs.x + x - item->coords.x1;
|
||||
int32_t diff_y = hint->grid_abs.y + y - item->coords.y1;
|
||||
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, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Place the grid track according to align methods. It keeps the track sizes but sets their position.
|
||||
* It can process both columns or rows according to the passed parameters.
|
||||
* @param cont_size size of the containers content area (width/height)
|
||||
* @param auto_size true: the container has auto size in the current direction
|
||||
* @param align align method
|
||||
* @param gap grid gap
|
||||
* @param track_num number of tracks
|
||||
* @param size_array array with the track sizes
|
||||
* @param pos_array write the positions of the tracks here
|
||||
* @return the total size of the grid
|
||||
*/
|
||||
static int32_t grid_align(int32_t cont_size, bool auto_size, lv_grid_align_t align, int32_t gap,
|
||||
uint32_t track_num,
|
||||
int32_t * size_array, int32_t * pos_array, bool reverse)
|
||||
{
|
||||
int32_t grid_size = 0;
|
||||
uint32_t i;
|
||||
|
||||
if(auto_size) {
|
||||
pos_array[0] = 0;
|
||||
}
|
||||
else {
|
||||
/*With spaced alignment gap will be calculated from the remaining space*/
|
||||
if(align == LV_GRID_ALIGN_SPACE_AROUND || align == LV_GRID_ALIGN_SPACE_BETWEEN || align == LV_GRID_ALIGN_SPACE_EVENLY) {
|
||||
gap = 0;
|
||||
if(track_num == 1) align = LV_GRID_ALIGN_CENTER;
|
||||
}
|
||||
|
||||
/*Get the full grid size with gap*/
|
||||
for(i = 0; i < track_num; i++) {
|
||||
grid_size += size_array[i] + gap;
|
||||
}
|
||||
grid_size -= gap;
|
||||
|
||||
/*Calculate the position of the first item and set gap is necessary*/
|
||||
switch(align) {
|
||||
case LV_GRID_ALIGN_START:
|
||||
pos_array[0] = 0;
|
||||
break;
|
||||
case LV_GRID_ALIGN_CENTER:
|
||||
pos_array[0] = (cont_size - grid_size) / 2;
|
||||
break;
|
||||
case LV_GRID_ALIGN_END:
|
||||
pos_array[0] = cont_size - grid_size;
|
||||
break;
|
||||
case LV_GRID_ALIGN_SPACE_BETWEEN:
|
||||
pos_array[0] = 0;
|
||||
gap = (int32_t)(cont_size - grid_size) / (int32_t)(track_num - 1);
|
||||
break;
|
||||
case LV_GRID_ALIGN_SPACE_AROUND:
|
||||
gap = (int32_t)(cont_size - grid_size) / (int32_t)(track_num);
|
||||
pos_array[0] = gap / 2;
|
||||
break;
|
||||
case LV_GRID_ALIGN_SPACE_EVENLY:
|
||||
gap = (int32_t)(cont_size - grid_size) / (int32_t)(track_num + 1);
|
||||
pos_array[0] = gap;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*Set the position of all tracks from the start position, gaps and track sizes*/
|
||||
for(i = 0; i < track_num - 1; i++) {
|
||||
pos_array[i + 1] = pos_array[i] + size_array[i] + gap;
|
||||
}
|
||||
|
||||
int32_t total_gird_size = pos_array[track_num - 1] + size_array[track_num - 1] - pos_array[0];
|
||||
|
||||
if(reverse) {
|
||||
for(i = 0; i < track_num; i++) {
|
||||
pos_array[i] = cont_size - pos_array[i] - size_array[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*Return the full size of the grid*/
|
||||
return total_gird_size;
|
||||
}
|
||||
|
||||
static uint32_t count_tracks(const int32_t * templ)
|
||||
{
|
||||
uint32_t i;
|
||||
for(i = 0; templ[i] != LV_GRID_TEMPLATE_LAST; i++);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
#endif /*LV_USE_GRID*/
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* @file lv_grid.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_GRID_H
|
||||
#define LV_GRID_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../../lv_conf_internal.h"
|
||||
#include "../../misc/lv_area.h"
|
||||
|
||||
#if LV_USE_GRID
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
/**
|
||||
* 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)
|
||||
LV_EXPORT_CONST_INT(LV_GRID_CONTENT);
|
||||
|
||||
#define LV_GRID_TEMPLATE_LAST (LV_COORD_MAX)
|
||||
LV_EXPORT_CONST_INT(LV_GRID_TEMPLATE_LAST);
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/*Can't include lv_obj.h because it includes this header file*/
|
||||
|
||||
typedef enum {
|
||||
LV_GRID_ALIGN_START,
|
||||
LV_GRID_ALIGN_CENTER,
|
||||
LV_GRID_ALIGN_END,
|
||||
LV_GRID_ALIGN_STRETCH,
|
||||
LV_GRID_ALIGN_SPACE_EVENLY,
|
||||
LV_GRID_ALIGN_SPACE_AROUND,
|
||||
LV_GRID_ALIGN_SPACE_BETWEEN,
|
||||
} lv_grid_align_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
void lv_grid_init(void);
|
||||
|
||||
void lv_obj_set_grid_dsc_array(lv_obj_t * obj, const int32_t col_dsc[], const int32_t row_dsc[]);
|
||||
|
||||
void lv_obj_set_grid_align(lv_obj_t * obj, lv_grid_align_t column_align, lv_grid_align_t row_align);
|
||||
|
||||
/**
|
||||
* Set the cell of an object. The object's parent needs to have grid layout, else nothing will happen
|
||||
* @param obj pointer to an object
|
||||
* @param column_align the vertical alignment in the cell. `LV_GRID_START/END/CENTER/STRETCH`
|
||||
* @param col_pos column ID
|
||||
* @param col_span number of columns to take (>= 1)
|
||||
* @param row_align the horizontal alignment in the cell. `LV_GRID_START/END/CENTER/STRETCH`
|
||||
* @param row_pos row ID
|
||||
* @param row_span number of rows to take (>= 1)
|
||||
*/
|
||||
void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_align_t column_align, int32_t col_pos, int32_t col_span,
|
||||
lv_grid_align_t row_align, int32_t row_pos, int32_t row_span);
|
||||
|
||||
/**
|
||||
* Just a wrapper to `LV_GRID_FR` for bindings.
|
||||
*/
|
||||
int32_t lv_grid_fr(uint8_t x);
|
||||
|
||||
/**********************
|
||||
* GLOBAL VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*LV_USE_GRID*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_GRID_H*/
|
||||
79
software/Power_Pico/Middlewares/LVGL/src/layouts/lv_layout.c
Normal file
79
software/Power_Pico/Middlewares/LVGL/src/layouts/lv_layout.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @file lv_layout.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_layout_private.h"
|
||||
#include "../core/lv_global.h"
|
||||
#include "../core/lv_obj.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define layout_cnt LV_GLOBAL_DEFAULT()->layout_count
|
||||
#define layout_list_def LV_GLOBAL_DEFAULT()->layout_list
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
void lv_layout_init(void)
|
||||
{
|
||||
/*Malloc a list for the built in layouts*/
|
||||
layout_list_def = lv_malloc(layout_cnt * sizeof(lv_layout_dsc_t));
|
||||
|
||||
#if LV_USE_FLEX
|
||||
lv_flex_init();
|
||||
#endif
|
||||
|
||||
#if LV_USE_GRID
|
||||
lv_grid_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void lv_layout_deinit(void)
|
||||
{
|
||||
lv_free(layout_list_def);
|
||||
}
|
||||
|
||||
uint32_t lv_layout_register(lv_layout_update_cb_t cb, void * user_data)
|
||||
{
|
||||
layout_list_def = lv_realloc(layout_list_def, (layout_cnt + 1) * sizeof(lv_layout_dsc_t));
|
||||
LV_ASSERT_MALLOC(layout_list_def);
|
||||
|
||||
layout_list_def[layout_cnt].cb = cb;
|
||||
layout_list_def[layout_cnt].user_data = user_data;
|
||||
return layout_cnt++;
|
||||
}
|
||||
|
||||
void lv_layout_apply(lv_obj_t * obj)
|
||||
{
|
||||
lv_layout_t layout_id = lv_obj_get_style_layout(obj, LV_PART_MAIN);
|
||||
if(layout_id > 0 && layout_id <= layout_cnt) {
|
||||
void * user_data = layout_list_def[layout_id].user_data;
|
||||
layout_list_def[layout_id].cb(obj, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
67
software/Power_Pico/Middlewares/LVGL/src/layouts/lv_layout.h
Normal file
67
software/Power_Pico/Middlewares/LVGL/src/layouts/lv_layout.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* @file lv_layout.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_LAYOUT_H
|
||||
#define LV_LAYOUT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../lv_conf_internal.h"
|
||||
#include "../misc/lv_types.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
typedef void (*lv_layout_update_cb_t)(lv_obj_t *, void * user_data);
|
||||
|
||||
typedef enum {
|
||||
LV_LAYOUT_NONE = 0,
|
||||
|
||||
#if LV_USE_FLEX
|
||||
LV_LAYOUT_FLEX,
|
||||
#endif
|
||||
|
||||
#if LV_USE_GRID
|
||||
LV_LAYOUT_GRID,
|
||||
#endif
|
||||
|
||||
LV_LAYOUT_LAST
|
||||
} lv_layout_t;
|
||||
|
||||
/**
|
||||
* Register a new layout
|
||||
* @param cb the layout update callback
|
||||
* @param user_data custom data that will be passed to `cb`
|
||||
* @return the ID of the new layout
|
||||
*/
|
||||
uint32_t lv_layout_register(lv_layout_update_cb_t cb, void * user_data);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#if LV_USE_FLEX
|
||||
#include "flex/lv_flex.h"
|
||||
#endif /* LV_USE_FLEX */
|
||||
|
||||
#if LV_USE_GRID
|
||||
#include "grid/lv_grid.h"
|
||||
#endif /* LV_USE_GRID */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_LAYOUT_H*/
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @file lv_layout_private.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_LAYOUT_PRIVATE_H
|
||||
#define LV_LAYOUT_PRIVATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
#include "lv_layout.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
typedef struct {
|
||||
lv_layout_update_cb_t cb;
|
||||
void * user_data;
|
||||
} lv_layout_dsc_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
void lv_layout_init(void);
|
||||
|
||||
void lv_layout_deinit(void);
|
||||
|
||||
/**
|
||||
* Update the layout of a widget
|
||||
* @param obj pointer to a widget
|
||||
*/
|
||||
void lv_layout_apply(lv_obj_t * obj);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_LAYOUT_PRIVATE_H*/
|
||||
Reference in New Issue
Block a user