mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
parent
b06393747f
commit
3fb8baf503
@ -843,6 +843,15 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if LV_USE_SPINNER
|
||||
else if(lv_obj_check_type(obj, &lv_spinner_class)) {
|
||||
lv_obj_add_style(obj, &styles->arc_indic, 0);
|
||||
lv_obj_add_style(obj, &styles->arc_indic, LV_PART_INDICATOR);
|
||||
lv_obj_add_style(obj, &styles->arc_indic_primary, LV_PART_INDICATOR);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LV_USE_METER
|
||||
else if(lv_obj_check_type(obj, &lv_meter_class)) {
|
||||
lv_obj_add_style(obj, &styles->card, 0);
|
||||
@ -878,6 +887,18 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LV_USE_CALENDAR_HEADER_ARROW
|
||||
else if(lv_obj_check_type(obj, &lv_calendar_header_arrow_class)) {
|
||||
lv_obj_add_style(obj, &styles->card, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LV_USE_CALENDAR_HEADER_DROPDOWN
|
||||
else if(lv_obj_check_type(obj, &lv_calendar_header_dropdown_class)) {
|
||||
lv_obj_add_style(obj, &styles->card, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LV_USE_KEYBOARD
|
||||
else if(lv_obj_check_type(obj, &lv_keyboard_class)) {
|
||||
lv_obj_add_style(obj, &styles->scr, 0);
|
||||
|
@ -29,6 +29,9 @@ extern "C" {
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
extern const lv_obj_class_t lv_animimg_class;
|
||||
|
||||
/*Data of image*/
|
||||
typedef struct {
|
||||
lv_img_t img;
|
||||
|
@ -25,12 +25,20 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void my_constructor(lv_obj_class_t * class_p, lv_obj_t * obj);
|
||||
static void month_event_cb(lv_event_t * e);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
const lv_obj_class_t lv_calendar_header_arrow_class = {
|
||||
.base_class = &lv_obj_class,
|
||||
.constructor_cb = my_constructor
|
||||
};
|
||||
|
||||
static const char * month_names_def[12] = LV_CALENDAR_DEFAULT_MONTH_NAMES;
|
||||
static lv_obj_t * calendar_param;
|
||||
static lv_coord_t btn_size_param;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@ -42,51 +50,60 @@ static const char * month_names_def[12] = LV_CALENDAR_DEFAULT_MONTH_NAMES;
|
||||
|
||||
lv_obj_t * lv_calendar_header_arrow_create(lv_obj_t * parent, lv_obj_t * calendar, lv_coord_t btn_size)
|
||||
{
|
||||
lv_obj_t * header = lv_obj_create(parent);
|
||||
|
||||
/*Use the same paddings as the calendar*/
|
||||
lv_obj_set_style_pad_left(header, lv_obj_get_style_pad_left(calendar, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_right(header, lv_obj_get_style_pad_right(calendar, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_top(header, lv_obj_get_style_pad_top(calendar, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_bottom(header, lv_obj_get_style_pad_bottom(calendar, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_column(header, lv_obj_get_style_pad_column(calendar, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_radius(header, lv_obj_get_style_radius(calendar, LV_PART_MAIN), 0);
|
||||
|
||||
const lv_calendar_date_t * cur_date = lv_calendar_get_showed_date(calendar);
|
||||
|
||||
lv_obj_update_layout(calendar);
|
||||
lv_coord_t w = lv_obj_get_width(calendar);
|
||||
lv_obj_set_size(header, w, LV_SIZE_CONTENT);
|
||||
lv_obj_set_flex_flow(header, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_flex_align(header, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START);
|
||||
|
||||
lv_obj_t * mo_prev = lv_btn_create(header);
|
||||
lv_obj_set_style_bg_img_src(mo_prev, LV_SYMBOL_LEFT, 0);
|
||||
lv_obj_set_size(mo_prev, btn_size, btn_size);
|
||||
lv_obj_add_event_cb(mo_prev, month_event_cb, LV_EVENT_CLICKED, calendar);
|
||||
lv_obj_clear_flag(mo_prev, LV_OBJ_FLAG_CLICK_FOCUSABLE);
|
||||
|
||||
lv_obj_t * label = lv_label_create(header);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||
lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_obj_set_flex_grow(label, 1);
|
||||
lv_label_set_text_fmt(label, "%d %s", cur_date->year, month_names_def[cur_date->month - 1]);
|
||||
|
||||
lv_obj_t * mo_next = lv_btn_create(header);
|
||||
lv_obj_set_style_bg_img_src(mo_next, LV_SYMBOL_RIGHT, 0);
|
||||
lv_obj_set_size(mo_next, btn_size, btn_size);
|
||||
lv_obj_add_event_cb(mo_next, month_event_cb, LV_EVENT_CLICKED, calendar);
|
||||
lv_obj_clear_flag(mo_next, LV_OBJ_FLAG_CLICK_FOCUSABLE);
|
||||
|
||||
lv_obj_align_to(header, calendar, LV_ALIGN_OUT_TOP_MID, 0, 0);
|
||||
|
||||
return header;
|
||||
calendar_param = calendar;
|
||||
btn_size_param = btn_size;
|
||||
lv_obj_t * obj = lv_obj_class_create_obj(&lv_calendar_header_arrow_class, parent);
|
||||
lv_obj_class_init_obj(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static void my_constructor(lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
{
|
||||
LV_TRACE_OBJ_CREATE("begin");
|
||||
|
||||
LV_UNUSED(class_p);
|
||||
|
||||
/*Use the same paddings as the calendar_param*/
|
||||
lv_obj_set_style_pad_left(obj, lv_obj_get_style_pad_left(calendar_param, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_right(obj, lv_obj_get_style_pad_right(calendar_param, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_top(obj, lv_obj_get_style_pad_top(calendar_param, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_bottom(obj, lv_obj_get_style_pad_bottom(calendar_param, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_column(obj, lv_obj_get_style_pad_column(calendar_param, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_radius(obj, lv_obj_get_style_radius(calendar_param, LV_PART_MAIN), 0);
|
||||
|
||||
const lv_calendar_date_t * cur_date = lv_calendar_get_showed_date(calendar_param);
|
||||
|
||||
lv_obj_update_layout(calendar_param);
|
||||
lv_coord_t w = lv_obj_get_width(calendar_param);
|
||||
lv_obj_set_size(obj, w, LV_SIZE_CONTENT);
|
||||
lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_flex_align(obj, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START);
|
||||
|
||||
lv_obj_t * mo_prev = lv_btn_create(obj);
|
||||
lv_obj_set_style_bg_img_src(mo_prev, LV_SYMBOL_LEFT, 0);
|
||||
lv_obj_set_size(mo_prev, btn_size_param, btn_size_param);
|
||||
lv_obj_add_event_cb(mo_prev, month_event_cb, LV_EVENT_CLICKED, calendar_param);
|
||||
lv_obj_clear_flag(mo_prev, LV_OBJ_FLAG_CLICK_FOCUSABLE);
|
||||
|
||||
lv_obj_t * label = lv_label_create(obj);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||
lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_obj_set_flex_grow(label, 1);
|
||||
lv_label_set_text_fmt(label, "%d %s", cur_date->year, month_names_def[cur_date->month - 1]);
|
||||
|
||||
lv_obj_t * mo_next = lv_btn_create(obj);
|
||||
lv_obj_set_style_bg_img_src(mo_next, LV_SYMBOL_RIGHT, 0);
|
||||
lv_obj_set_size(mo_next, btn_size_param, btn_size_param);
|
||||
lv_obj_add_event_cb(mo_next, month_event_cb, LV_EVENT_CLICKED, calendar_param);
|
||||
lv_obj_clear_flag(mo_next, LV_OBJ_FLAG_CLICK_FOCUSABLE);
|
||||
|
||||
lv_obj_align_to(obj, calendar_param, LV_ALIGN_OUT_TOP_MID, 0, 0);
|
||||
}
|
||||
|
||||
static void month_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * btn = lv_event_get_target(e);
|
||||
|
@ -23,6 +23,7 @@ extern "C" {
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
extern const lv_obj_class_t lv_calendar_header_arrow_class;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @file lv_calendar_header_dropdown.c
|
||||
* @file lv_calendar_obj_dropdown.c
|
||||
*
|
||||
*/
|
||||
|
||||
@ -24,12 +24,18 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void my_constructor(lv_obj_class_t * class_p, lv_obj_t * obj);
|
||||
static void year_event_cb(lv_event_t * e);
|
||||
static void month_event_cb(lv_event_t * e);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
const lv_obj_class_t lv_calendar_header_dropdown_class = {
|
||||
.base_class = &lv_obj_class,
|
||||
.constructor_cb = my_constructor
|
||||
};
|
||||
|
||||
static const char * month_list = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12";
|
||||
static const char * year_list = {
|
||||
"2023\n2022\n2021\n"
|
||||
@ -41,6 +47,8 @@ static const char * year_list = {
|
||||
"1920\n1919\n1918\n1917\n1916\n1915\n1914\n1913\n1912\n1911\n1910\n1909\n1908\n1907\n1906\n1905\n1904\n1903\n1902\n1901"
|
||||
};
|
||||
|
||||
static lv_obj_t * calendar_param;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
@ -51,45 +59,55 @@ static const char * year_list = {
|
||||
|
||||
lv_obj_t * lv_calendar_header_dropdown_create(lv_obj_t * parent, lv_obj_t * calendar)
|
||||
{
|
||||
lv_obj_t * header = lv_obj_create(parent);
|
||||
calendar_param = calendar;
|
||||
lv_obj_t * obj = lv_obj_class_create_obj(&lv_calendar_header_dropdown_class, parent);
|
||||
lv_obj_class_init_obj(obj);
|
||||
|
||||
/*Use the same paddings as the calendar*/
|
||||
lv_obj_set_style_pad_left(header,lv_obj_get_style_pad_left(calendar, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_right(header,lv_obj_get_style_pad_right(calendar, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_top(header,lv_obj_get_style_pad_top(calendar, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_bottom(header,lv_obj_get_style_pad_bottom(calendar, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_column(header,lv_obj_get_style_pad_column(calendar, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_radius(header,lv_obj_get_style_radius(calendar, LV_PART_MAIN), 0);
|
||||
|
||||
const lv_calendar_date_t * cur_date = lv_calendar_get_showed_date(calendar);
|
||||
|
||||
lv_obj_update_layout(calendar);
|
||||
lv_coord_t w = lv_obj_get_width(calendar);
|
||||
lv_obj_set_size(header, w, LV_SIZE_CONTENT);
|
||||
lv_obj_set_flex_flow(header, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_flex_align(header, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START);
|
||||
|
||||
lv_obj_t * year_dd = lv_dropdown_create(header);
|
||||
lv_dropdown_set_options(year_dd, year_list);
|
||||
lv_dropdown_set_selected(year_dd, 2023 - cur_date->year);
|
||||
lv_obj_add_event_cb(year_dd, year_event_cb, LV_EVENT_VALUE_CHANGED, calendar);
|
||||
lv_obj_set_flex_grow(year_dd, 1);
|
||||
|
||||
lv_obj_t * month_dd = lv_dropdown_create(header);
|
||||
lv_dropdown_set_options(month_dd, month_list);
|
||||
lv_dropdown_set_selected(month_dd, cur_date->month - 1);
|
||||
lv_obj_add_event_cb(month_dd, month_event_cb, LV_EVENT_VALUE_CHANGED, calendar);
|
||||
lv_obj_set_flex_grow(month_dd, 1);
|
||||
|
||||
lv_obj_align_to(header, calendar, LV_ALIGN_OUT_TOP_MID, 0, 0);
|
||||
|
||||
return header;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static void my_constructor(lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
{
|
||||
LV_TRACE_OBJ_CREATE("begin");
|
||||
|
||||
LV_UNUSED(class_p);
|
||||
|
||||
/*Use the same paddings as the calendar_param*/
|
||||
lv_obj_set_style_pad_left(obj,lv_obj_get_style_pad_left(calendar_param, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_right(obj,lv_obj_get_style_pad_right(calendar_param, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_top(obj,lv_obj_get_style_pad_top(calendar_param, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_bottom(obj,lv_obj_get_style_pad_bottom(calendar_param, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_pad_column(obj,lv_obj_get_style_pad_column(calendar_param, LV_PART_MAIN), 0);
|
||||
lv_obj_set_style_radius(obj,lv_obj_get_style_radius(calendar_param, LV_PART_MAIN), 0);
|
||||
|
||||
const lv_calendar_date_t * cur_date = lv_calendar_get_showed_date(calendar_param);
|
||||
|
||||
lv_obj_update_layout(calendar_param);
|
||||
lv_coord_t w = lv_obj_get_width(calendar_param);
|
||||
lv_obj_set_size(obj, w, LV_SIZE_CONTENT);
|
||||
lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_flex_align(obj, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START);
|
||||
|
||||
lv_obj_t * year_dd = lv_dropdown_create(obj);
|
||||
lv_dropdown_set_options(year_dd, year_list);
|
||||
lv_dropdown_set_selected(year_dd, 2023 - cur_date->year);
|
||||
lv_obj_add_event_cb(year_dd, year_event_cb, LV_EVENT_VALUE_CHANGED, calendar_param);
|
||||
lv_obj_set_flex_grow(year_dd, 1);
|
||||
|
||||
lv_obj_t * month_dd = lv_dropdown_create(obj);
|
||||
lv_dropdown_set_options(month_dd, month_list);
|
||||
lv_dropdown_set_selected(month_dd, cur_date->month - 1);
|
||||
lv_obj_add_event_cb(month_dd, month_event_cb, LV_EVENT_VALUE_CHANGED, calendar_param);
|
||||
lv_obj_set_flex_grow(month_dd, 1);
|
||||
|
||||
lv_obj_align_to(obj, calendar_param, LV_ALIGN_OUT_TOP_MID, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
static void month_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * dropdown = lv_event_get_target(e);
|
||||
|
@ -23,6 +23,7 @@ extern "C" {
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
extern const lv_obj_class_t lv_calendar_header_dropdown_class;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
@ -34,6 +35,7 @@ extern "C" {
|
||||
* @return pointer to the created calendar
|
||||
*/
|
||||
lv_obj_t * lv_calendar_header_dropdown_create(lv_obj_t * parent, lv_obj_t * calendar);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
@ -20,12 +20,20 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void lv_spinner_constructor(lv_obj_class_t * class_p, lv_obj_t * obj);
|
||||
static void arc_anim_start_angle(void * obj, int32_t v);
|
||||
static void arc_anim_end_angle(void * obj, int32_t v);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
const lv_obj_class_t lv_spinner_class = {
|
||||
.base_class = &lv_arc_class,
|
||||
.constructor_cb = lv_spinner_constructor
|
||||
};
|
||||
|
||||
static uint32_t time_param;
|
||||
static uint32_t arc_length_param;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@ -42,20 +50,32 @@ static void arc_anim_end_angle(void * obj, int32_t v);
|
||||
*/
|
||||
lv_obj_t * lv_spinner_create(lv_obj_t * parent, uint32_t time, uint32_t arc_length)
|
||||
{
|
||||
/*Create the ancestor of spinner*/
|
||||
lv_obj_t * spinner = lv_arc_create(parent);
|
||||
LV_ASSERT_MALLOC(spinner);
|
||||
if(spinner == NULL) return NULL;
|
||||
time_param = time;
|
||||
arc_length_param = arc_length;
|
||||
|
||||
lv_obj_remove_style(spinner, NULL, LV_PART_KNOB | LV_STATE_ANY);
|
||||
lv_obj_t * obj = lv_obj_class_create_obj(&lv_spinner_class, parent);
|
||||
lv_obj_class_init_obj(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static void lv_spinner_constructor(lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
{
|
||||
LV_TRACE_OBJ_CREATE("begin");
|
||||
|
||||
LV_UNUSED(class_p);
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, spinner);
|
||||
lv_anim_set_var(&a, obj);
|
||||
lv_anim_set_exec_cb(&a, arc_anim_end_angle);
|
||||
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
|
||||
lv_anim_set_time(&a, time);
|
||||
lv_anim_set_values(&a, arc_length, 360 + arc_length);
|
||||
lv_anim_set_time(&a, time_param);
|
||||
lv_anim_set_values(&a, arc_length_param, 360 + arc_length_param);
|
||||
lv_anim_start(&a);
|
||||
|
||||
lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out);
|
||||
@ -63,17 +83,11 @@ lv_obj_t * lv_spinner_create(lv_obj_t * parent, uint32_t time, uint32_t arc_leng
|
||||
lv_anim_set_exec_cb(&a, arc_anim_start_angle);
|
||||
lv_anim_start(&a);
|
||||
|
||||
lv_arc_set_bg_angles(spinner, 0, 360);
|
||||
lv_arc_set_rotation(spinner, 270);
|
||||
|
||||
return spinner;
|
||||
lv_arc_set_bg_angles(obj, 0, 360);
|
||||
lv_arc_set_rotation(obj, 270);
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static void arc_anim_start_angle(void * obj, int32_t v)
|
||||
{
|
||||
lv_arc_set_start_angle(obj, (uint16_t) v);
|
||||
|
@ -29,6 +29,7 @@ extern "C" {
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
extern const lv_obj_class_t lv_spinner_class;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
|
@ -28,6 +28,8 @@ extern "C" {
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
extern const lv_obj_class_t lv_canvas_class;
|
||||
|
||||
/*Data of canvas*/
|
||||
typedef struct {
|
||||
lv_img_t img;
|
||||
|
Loading…
x
Reference in New Issue
Block a user