fix(btnmatrix): join active, pressed and focused button into active button
This commit is contained in:
@@ -18,12 +18,13 @@ void lv_example_scroll_2(void)
|
||||
{
|
||||
lv_obj_t * list = lv_obj_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_size(list, 280, 150);
|
||||
lv_obj_set_scroll_snap_align_x(list, LV_SCROLL_SNAP_ALIGN_CENTER);
|
||||
lv_obj_set_scroll_snap_x(list, LV_SCROLL_SNAP_CENTER);
|
||||
lv_obj_set_layout(list, &lv_flex_queue);
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; i < 10; i++) {
|
||||
lv_obj_t * btn = lv_btn_create(list, NULL);
|
||||
lv_obj_clear_flag(btn, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /* It does similar thing than snapping so disable it.*/
|
||||
lv_obj_set_size(btn, 150, 100);
|
||||
|
||||
lv_obj_t * label = lv_label_create(btn, NULL);
|
||||
|
||||
@@ -10,7 +10,7 @@ static void event_cb(lv_obj_t * obj, lv_event_t e)
|
||||
/*Change the draw descriptor the 2nd button */
|
||||
if(dsc->id == 1) {
|
||||
dsc->rect_dsc->radius = 0;
|
||||
if(lv_btnmatrix_get_pressed_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_color_blue_darken_3();
|
||||
if(lv_btnmatrix_get_active_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_color_blue_darken_3();
|
||||
else dsc->rect_dsc->bg_color = lv_color_blue();
|
||||
|
||||
dsc->rect_dsc->shadow_width = 6;
|
||||
@@ -21,7 +21,7 @@ static void event_cb(lv_obj_t * obj, lv_event_t e)
|
||||
/*Change the draw descriptor the 3rd button */
|
||||
else if(dsc->id == 2) {
|
||||
dsc->rect_dsc->radius = LV_RADIUS_CIRCLE;
|
||||
if(lv_btnmatrix_get_pressed_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_color_red_darken_3();
|
||||
if(lv_btnmatrix_get_active_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_color_red_darken_3();
|
||||
else dsc->rect_dsc->bg_color = lv_color_red();
|
||||
|
||||
dsc->label_dsc->color = lv_color_white();
|
||||
@@ -50,7 +50,7 @@ static void event_cb(lv_obj_t * obj, lv_event_t e)
|
||||
lv_draw_img_dsc_t img_draw_dsc;
|
||||
lv_draw_img_dsc_init(&img_draw_dsc);
|
||||
img_draw_dsc.recolor = lv_color_black();
|
||||
if(lv_btnmatrix_get_pressed_btn(obj) == dsc->id) img_draw_dsc.recolor_opa = LV_OPA_30;
|
||||
if(lv_btnmatrix_get_active_btn(obj) == dsc->id) img_draw_dsc.recolor_opa = LV_OPA_30;
|
||||
|
||||
lv_draw_img(&a, dsc->clip_area, &img_star, &img_draw_dsc);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ static void event_handler(lv_obj_t * obj, lv_event_t event)
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
lv_calendar_date_t date;
|
||||
if(lv_calendar_get_pressed_date(obj, &date)) {
|
||||
LV_LOG_USER("Clicked date: %02d.%02d.%d\n", date.day, date.month, date.year);
|
||||
LV_LOG_USER("Clicked date: %02d.%02d.%d", date.day, date.month, date.year);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@ static void event_handler(lv_obj_t * obj, lv_event_t event)
|
||||
void lv_example_calendar_1(void)
|
||||
{
|
||||
lv_obj_t * calendar = lv_calendar_create(lv_scr_act());
|
||||
lv_obj_set_size(calendar, 180, 180);
|
||||
lv_obj_align(calendar, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_set_size(calendar, 200, 200);
|
||||
lv_obj_align(calendar, NULL, LV_ALIGN_CENTER, 0, 20);
|
||||
lv_obj_add_event_cb(calendar, event_handler, NULL);
|
||||
|
||||
/*Set today's date*/
|
||||
@@ -29,16 +29,16 @@ void lv_example_calendar_1(void)
|
||||
|
||||
/*Highlight a few days*/
|
||||
static lv_calendar_date_t highlighted_days[3]; /*Only its pointer will be saved so should be static*/
|
||||
highlighted_days[0].year = 2020;
|
||||
highlighted_days[0].month = 10;
|
||||
highlighted_days[0].year = 2021;
|
||||
highlighted_days[0].month = 02;
|
||||
highlighted_days[0].day = 6;
|
||||
|
||||
highlighted_days[1].year = 2020;
|
||||
highlighted_days[1].month = 10;
|
||||
highlighted_days[1].year = 2021;
|
||||
highlighted_days[1].month = 02;
|
||||
highlighted_days[1].day = 11;
|
||||
|
||||
highlighted_days[2].year = 2020;
|
||||
highlighted_days[2].month = 11;
|
||||
highlighted_days[2].year = 2022;
|
||||
highlighted_days[2].month = 02;
|
||||
highlighted_days[2].day = 22;
|
||||
|
||||
lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3);
|
||||
|
||||
@@ -24,11 +24,11 @@ void lv_example_meter_4(void)
|
||||
lv_meter_set_indicator_start_value(meter, indic1, 0);
|
||||
lv_meter_set_indicator_end_value(meter, indic1, 40);
|
||||
|
||||
lv_meter_indicator_t * indic2 = lv_meter_add_arc(meter, scale, indic_w, lv_color_green(), 0);
|
||||
lv_meter_indicator_t * indic2 = lv_meter_add_arc(meter, scale, indic_w, lv_color_yellow(), 0);
|
||||
lv_meter_set_indicator_start_value(meter, indic2, 40); /*Start from the previous*/
|
||||
lv_meter_set_indicator_end_value(meter, indic2, 80);
|
||||
|
||||
lv_meter_indicator_t * indic3 = lv_meter_add_arc(meter, scale, indic_w, lv_color_blue(), 0);
|
||||
lv_meter_indicator_t * indic3 = lv_meter_add_arc(meter, scale, indic_w, lv_color_deep_orange(), 0);
|
||||
lv_meter_set_indicator_start_value(meter, indic3, 80); /*Start from the previous*/
|
||||
lv_meter_set_indicator_end_value(meter, indic3, 100);
|
||||
}
|
||||
|
||||
74
examples/widgets/table/lv_example_table_2.c
Normal file
74
examples/widgets/table/lv_example_table_2.c
Normal file
@@ -0,0 +1,74 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_TABLE && LV_BUILD_EXAMPLES
|
||||
|
||||
#define ITEM_CNT 200
|
||||
|
||||
static void event_cb(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
if(e == LV_EVENT_DRAW_PART_END) {
|
||||
lv_obj_draw_hook_dsc_t * hook_dsc = lv_event_get_param();
|
||||
/*If the cells are drawn...*/
|
||||
if(hook_dsc->part == LV_PART_ITEMS) {
|
||||
uint32_t row = hook_dsc->id;
|
||||
|
||||
/*Make the texts in the first cell center aligned*/
|
||||
if(row == 0) {
|
||||
hook_dsc->label_dsc->align = LV_TEXT_ALIGN_CENTER;
|
||||
hook_dsc->rect_dsc->bg_color = lv_color_mix(lv_color_blue(), hook_dsc->rect_dsc->bg_color, LV_OPA_20);
|
||||
hook_dsc->rect_dsc->bg_opa = LV_OPA_COVER;
|
||||
}
|
||||
|
||||
/*Make every 2nd row grayish*/
|
||||
if((row != 0 && row % 2) == 0) {
|
||||
hook_dsc->rect_dsc->bg_color = lv_color_mix(lv_color_grey(), hook_dsc->rect_dsc->bg_color, LV_OPA_10);
|
||||
hook_dsc->rect_dsc->bg_opa = LV_OPA_COVER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A very light-weighted list created from table
|
||||
*/
|
||||
void lv_example_table_2(void)
|
||||
{
|
||||
/*Measure memory usage*/
|
||||
lv_mem_monitor_t mon1;
|
||||
lv_mem_monitor(&mon1);
|
||||
|
||||
uint32_t t = lv_tick_get();
|
||||
|
||||
lv_obj_t * table = lv_table_create(lv_scr_act(), NULL);
|
||||
lv_table_set_row_cnt(table, ITEM_CNT); /*Not required but avoids a lot of memory reallocation lv_table_set_set_value */
|
||||
lv_table_set_col_cnt(table, 1);
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; i < ITEM_CNT; i++) {
|
||||
lv_table_set_cell_value_fmt(table, i, 0, "Item %d", i + 1);
|
||||
}
|
||||
|
||||
/*Set a smaller height to the table. It'll make it scrollable*/
|
||||
lv_obj_set_height(table, 200);
|
||||
lv_obj_align(table, NULL, LV_ALIGN_CENTER, 0, -20);
|
||||
|
||||
/*Add an event callback to to apply some custom drawing*/
|
||||
// lv_obj_add_event_cb(table, event_cb, NULL);
|
||||
|
||||
lv_mem_monitor_t mon2;
|
||||
lv_mem_monitor(&mon2);
|
||||
|
||||
uint32_t mem_used = mon1.free_size - mon2.free_size;
|
||||
|
||||
uint32_t elaps = lv_tick_elaps(t);
|
||||
|
||||
lv_obj_t * label = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_label_set_text_fmt(label, "%d bytes are used by the table\n"
|
||||
"and %d items were added in %d ms",
|
||||
mem_used, ITEM_CNT, elaps);
|
||||
|
||||
lv_obj_align(label, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -10);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user