From 63bc72e53a02f764469478c209a36dda1618adb7 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 25 Mar 2021 19:59:23 +0100 Subject: [PATCH] minor fixes --- examples/styles/lv_example_style_5.c | 0 examples/widgets/bar/lv_example_bar_6.c | 28 +++++++++---------- examples/widgets/btn/lv_example_btn_1.c | 1 + examples/widgets/slider/lv_example_slider_2.c | 8 +++--- examples/widgets/slider/lv_example_slider_3.c | 8 +++--- src/core/lv_obj.c | 9 ++++++ src/core/lv_obj.h | 14 ++++++++-- src/core/lv_obj_draw.c | 20 ++++++------- src/extra/layouts/grid/lv_grid.h | 2 ++ src/widgets/lv_dropdown.c | 1 + 10 files changed, 54 insertions(+), 37 deletions(-) delete mode 100644 examples/styles/lv_example_style_5.c diff --git a/examples/styles/lv_example_style_5.c b/examples/styles/lv_example_style_5.c deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/widgets/bar/lv_example_bar_6.c b/examples/widgets/bar/lv_example_bar_6.c index 49c57e510..5037b16fb 100644 --- a/examples/widgets/bar/lv_example_bar_6.c +++ b/examples/widgets/bar/lv_example_bar_6.c @@ -1,11 +1,11 @@ -//#include "../../../lvgl.h" -//#if LV_USE_BAR && LV_BUILD_EXAMPLES -// +#include "../../../lvgl.h" +#if LV_USE_BAR && LV_BUILD_EXAMPLES + //static void set_value(void *bar, int32_t v) //{ // lv_bar_set_value(bar, v, LV_ANIM_OFF); //} -// + //static void event_cb(lv_obj_t * obj, lv_event_t e) //{ // if(e == LV_EVENT_DRAW_POST_END) { @@ -42,12 +42,12 @@ // lv_draw_label(&txt_area, clip_area, &dsc, buf, NULL); // } //} -// -///** -// * Custom drawer on bar to display the current value -// */ -//void lv_example_bar_6(void) -//{ + +/** + * Custom drawer on bar to display the current value + */ +void lv_example_bar_6(void) +{ // static lv_style_t style_bg; // lv_style_init(&style_bg); // lv_style_set_content_ofs_y(&style_bg, -3); @@ -67,7 +67,7 @@ // lv_anim_set_playback_time(&a, 2000); // lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); // lv_anim_start(&a); -// -//} -// -//#endif + +} + +#endif diff --git a/examples/widgets/btn/lv_example_btn_1.c b/examples/widgets/btn/lv_example_btn_1.c index 6b68c47ac..e338d1e29 100644 --- a/examples/widgets/btn/lv_example_btn_1.c +++ b/examples/widgets/btn/lv_example_btn_1.c @@ -33,5 +33,6 @@ void lv_example_btn_1(void) label = lv_label_create(btn2); lv_label_set_text(label, "Toggle"); lv_obj_center(label); + lv_label_set_text(label, "Togglasdasasdasdase"); } #endif diff --git a/examples/widgets/slider/lv_example_slider_2.c b/examples/widgets/slider/lv_example_slider_2.c index 59d93eacd..ddc619d78 100644 --- a/examples/widgets/slider/lv_example_slider_2.c +++ b/examples/widgets/slider/lv_example_slider_2.c @@ -1,4 +1,4 @@ -//#include "../../../lvgl.h" +#include "../../../lvgl.h" //#if LV_USE_SLIDER && LV_BUILD_EXAMPLES // //static void slider_event_cb(lv_obj_t * slider, lv_event_t event); @@ -9,8 +9,8 @@ ///** // * Show the current value when the slider if pressed using a fancy style transition. // */ -//void lv_example_slider_2(void) -//{ +void lv_example_slider_2(void) +{ // lv_style_init(&style_def); // lv_style_set_content_opa(&style_def, LV_OPA_TRANSP); // lv_style_set_content_align(&style_def, LV_ALIGN_OUT_TOP_MID); @@ -27,7 +27,7 @@ // // lv_obj_add_style(slider, LV_PART_KNOB, LV_STATE_DEFAULT, &style_def); // lv_obj_add_style(slider, LV_PART_KNOB, LV_STATE_PRESSED, &style_pr); -//} +} // //static void slider_event_cb(lv_obj_t * slider, lv_event_t event) //{ diff --git a/examples/widgets/slider/lv_example_slider_3.c b/examples/widgets/slider/lv_example_slider_3.c index 1e6ad812d..cc2b0e18b 100644 --- a/examples/widgets/slider/lv_example_slider_3.c +++ b/examples/widgets/slider/lv_example_slider_3.c @@ -1,4 +1,4 @@ -//#include "../../../lvgl.h" +#include "../../../lvgl.h" //#if LV_USE_SLIDER && LV_BUILD_EXAMPLES // //static void slider_event_cb(lv_obj_t * slider, lv_event_t event); @@ -7,8 +7,8 @@ // * Show the current value when the slider if pressed (using only styles). // * // */ -//void lv_example_slider_3(void) -//{ +void lv_example_slider_3(void) +{ // /*Create a slider in the center of the display*/ // lv_obj_t * slider; // slider = lv_slider_create(lv_scr_act()); @@ -25,7 +25,7 @@ // // /*To update the value text*/ // lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL); -//} +} // //static void slider_event_cb(lv_obj_t * slider, lv_event_t event) //{ diff --git a/src/core/lv_obj.c b/src/core/lv_obj.c index aa280e043..554d2adfa 100644 --- a/src/core/lv_obj.c +++ b/src/core/lv_obj.c @@ -22,6 +22,7 @@ #include "../misc/lv_math.h" #include "../misc/lv_log.h" #include "../hal/lv_hal.h" +#include "../extra/layouts/lv_layouts.h" #include #include @@ -155,6 +156,9 @@ void lv_init(void) LV_LOG_WARN("Log level is set the Trace which makes LVGL much slower") #endif + lv_grid_init(); + lv_flex_init(); + lv_initialized = true; LV_LOG_TRACE("finished"); @@ -585,6 +589,11 @@ bool lv_obj_has_class(const lv_obj_t * obj, const lv_obj_class_t * class_p) return false; } +const lv_obj_class_t * lv_obj_get_class(const lv_obj_t * obj) +{ + return obj->class_p; +} + bool lv_obj_is_valid(const lv_obj_t * obj) { lv_disp_t * disp = lv_disp_get_next(NULL); diff --git a/src/core/lv_obj.h b/src/core/lv_obj.h index 0fd5abdbf..9df09c642 100644 --- a/src/core/lv_obj.h +++ b/src/core/lv_obj.h @@ -483,13 +483,21 @@ lv_obj_t * lv_obj_get_focused_obj(const lv_obj_t * obj); bool lv_obj_check_type(const lv_obj_t * obj, const lv_obj_class_t * class_p); /** - * Check if any object has a given type + * Check if any object has a given class (type). + * It checks the ancestor classes too. * @param obj pointer to an object - * @param obj_type type of the object. (e.g. "lv_btn") - * @return true: valid + * @param class_p a class to check (e.g. `lv_slider_class`) + * @return true: `obj` has the given class */ bool lv_obj_has_class(const lv_obj_t * obj, const lv_obj_class_t * class_p); +/** + * Get the class (type) of the object + * @param obj pointer to an object + * @return the class (type) of the object + */ +const lv_obj_class_t * lv_obj_get_class(const lv_obj_t * obj); + /** * Check if any object is still "alive", and part of the hierarchy * @param obj pointer to an object diff --git a/src/core/lv_obj_draw.c b/src/core/lv_obj_draw.c index a05ef804c..963e522cd 100644 --- a/src/core/lv_obj_draw.c +++ b/src/core/lv_obj_draw.c @@ -165,21 +165,17 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t if(draw_dsc->bg_img_src) { draw_dsc->bg_img_opa = lv_obj_get_style_bg_img_opa(obj, part); if(draw_dsc->bg_img_opa > LV_OPA_MIN) { - draw_dsc->bg_img_tiled = lv_obj_get_style_bg_img_tiled(obj, part); + if(lv_img_src_get_type(draw_dsc->bg_img_src) == LV_IMG_SRC_SYMBOL) { + draw_dsc->bg_img_symbol_font= lv_obj_get_style_text_font(obj, part); + draw_dsc->bg_img_recolor = lv_obj_get_style_text_color(obj, part); + } else { + draw_dsc->bg_img_recolor = lv_obj_get_style_bg_img_recolor(obj, part); + draw_dsc->bg_img_recolor_opa = lv_obj_get_style_bg_img_recolor_opa(obj, part); + draw_dsc->bg_img_tiled = lv_obj_get_style_bg_img_tiled(obj, part); + } } } } - - draw_dsc->content_text = lv_obj_get_style_content_text(obj, part); - if(draw_dsc->content_text) { - draw_dsc->content_ofs_y = lv_obj_get_style_content_ofs_y(obj, part); - draw_dsc->content_ofs_x = lv_obj_get_style_content_ofs_x(obj, part); - draw_dsc->content_align = lv_obj_get_style_content_align(obj, part); - draw_dsc->content_font = lv_obj_get_style_content_font(obj, part); - draw_dsc->content_color = lv_obj_get_style_content_color_filtered(obj, part); - draw_dsc->content_letter_space = lv_obj_get_style_content_letter_space(obj, part); - draw_dsc->content_line_space = lv_obj_get_style_content_line_space(obj, part); - } #endif } diff --git a/src/extra/layouts/grid/lv_grid.h b/src/extra/layouts/grid/lv_grid.h index c5029ad32..d6d2d2646 100644 --- a/src/extra/layouts/grid/lv_grid.h +++ b/src/extra/layouts/grid/lv_grid.h @@ -65,6 +65,8 @@ extern lv_style_prop_t LV_STYLE_GRID_CELL_ROW_PLACE; * GLOBAL PROTOTYPES **********************/ +void lv_grid_init(void); + 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); diff --git a/src/widgets/lv_dropdown.c b/src/widgets/lv_dropdown.c index 898d7d8b3..f224a724c 100644 --- a/src/widgets/lv_dropdown.c +++ b/src/widgets/lv_dropdown.c @@ -6,6 +6,7 @@ /********************* * INCLUDES *********************/ +#include #include "lv_dropdown.h" #if LV_USE_DROPDOWN != 0