api(style) remove content style proeprties

This commit is contained in:
Gabor Kiss-Vamosi
2021-03-25 13:36:50 +01:00
parent b7becbbb22
commit 53f3cc1827
158 changed files with 701 additions and 1364 deletions

View File

@@ -3,7 +3,7 @@
void lv_example_bar_1(void)
{
lv_obj_t * bar1 = lv_bar_create(lv_scr_act(), NULL);
lv_obj_t * bar1 = lv_bar_create(lv_scr_act());
lv_obj_set_size(bar1, 200, 20);
lv_obj_align(bar1, NULL, LV_ALIGN_CENTER, 0, 0);
lv_bar_set_value(bar1, 70, LV_ANIM_OFF);

View File

@@ -21,7 +21,7 @@ void lv_example_bar_2(void)
lv_style_set_bg_color(&style_indic, lv_color_blue());
lv_style_set_radius(&style_indic, 3);
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);
lv_obj_t * bar = lv_bar_create(lv_scr_act());
lv_obj_remove_style(bar, LV_PART_ANY, LV_STATE_ANY, NULL); /*To have a clean start*/
lv_obj_add_style(bar, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg);
lv_obj_add_style(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, &style_indic);

View File

@@ -7,7 +7,7 @@ static void set_temp(void * bar, int32_t temp)
static char buf[10]; /*Only the pointer t saved so must be static*/
lv_snprintf(buf, sizeof(buf), "%d°C", temp);
lv_obj_set_style_content_text(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, buf);
// lv_obj_set_style_content_text(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, buf);
}
/**
@@ -22,11 +22,11 @@ void lv_example_bar_3(void)
lv_style_set_bg_color(&style_indic, lv_color_red());
lv_style_set_bg_grad_color(&style_indic, lv_color_blue());
lv_style_set_bg_grad_dir(&style_indic, LV_GRAD_DIR_VER);
lv_style_set_content_align(&style_indic, LV_ALIGN_OUT_LEFT_TOP);
lv_style_set_content_ofs_x(&style_indic, -3);
lv_style_set_content_color(&style_indic, lv_color_grey());
// lv_style_set_content_align(&style_indic, LV_ALIGN_OUT_LEFT_TOP);
// lv_style_set_content_ofs_x(&style_indic, -3);
// lv_style_set_content_color(&style_indic, lv_color_grey());
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);
lv_obj_t * bar = lv_bar_create(lv_scr_act());
lv_obj_add_style(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, &style_indic);
lv_obj_set_size(bar, 20, 200);
lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);

View File

@@ -14,7 +14,7 @@ void lv_example_bar_4(void)
lv_style_set_bg_img_tiled(&style_indic, true);
lv_style_set_bg_img_opa(&style_indic, LV_OPA_30);
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);
lv_obj_t * bar = lv_bar_create(lv_scr_act());
lv_obj_add_style(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, &style_indic);
lv_obj_set_size(bar, 260, 20);

View File

@@ -6,25 +6,20 @@
*/
void lv_example_bar_5(void)
{
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_content_ofs_y(&style_bg, -3);
lv_style_set_content_align(&style_bg, LV_ALIGN_OUT_TOP_MID);
lv_obj_t * bar_ltr = lv_bar_create(lv_scr_act(), NULL);
lv_obj_t * bar_ltr = lv_bar_create(lv_scr_act());
lv_obj_set_size(bar_ltr, 200, 20);
lv_bar_set_value(bar_ltr, 70, LV_ANIM_OFF);
lv_obj_align(bar_ltr, NULL, LV_ALIGN_CENTER, 0, -30);
lv_obj_add_style(bar_ltr, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg);
lv_obj_set_style_content_text(bar_ltr, LV_PART_MAIN, LV_STATE_DEFAULT, "Left to Right base direction");
// lv_obj_add_style(bar_ltr, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg);
// lv_obj_set_style_content_text(bar_ltr, LV_PART_MAIN, LV_STATE_DEFAULT, "Left to Right base direction");
lv_obj_t * bar_rtl = lv_bar_create(lv_scr_act(), NULL);
lv_obj_t * bar_rtl = lv_bar_create(lv_scr_act());
lv_obj_set_base_dir(bar_rtl, LV_BIDI_DIR_RTL);
lv_obj_set_size(bar_rtl, 200, 20);
lv_bar_set_value(bar_rtl, 70, LV_ANIM_OFF);
lv_obj_align(bar_rtl, NULL, LV_ALIGN_CENTER, 0, 30);
lv_obj_add_style(bar_rtl, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg);
lv_obj_set_style_content_text(bar_rtl, LV_PART_MAIN, LV_STATE_DEFAULT, "Right to Left base direction");
// lv_obj_add_style(bar_rtl, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg);
// lv_obj_set_style_content_text(bar_rtl, LV_PART_MAIN, LV_STATE_DEFAULT, "Right to Left base direction");
}
#endif

View File

@@ -1,73 +1,73 @@
#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) {
lv_bar_t * bar = (lv_bar_t *)obj;
lv_draw_label_dsc_t dsc;
lv_draw_label_dsc_init(&dsc);
dsc.font = LV_FONT_DEFAULT;
char buf[8];
lv_snprintf(buf, sizeof(buf), "%d", lv_bar_get_value(obj));
lv_point_t txt_size;
lv_txt_get_size(&txt_size, buf, dsc.font, dsc.letter_space, dsc.line_space, LV_COORD_MAX, dsc.flag);
lv_area_t txt_area;
/*If the indicator is long enough put the text inside on the right*/
if(lv_area_get_width(&bar->indic_area) > txt_size.x + 20) {
txt_area.x2 = bar->indic_area.x2 - 5;
txt_area.x1 = txt_area.x2 - txt_size.x + 1;
dsc.color = lv_color_white();
}
/*If the indicator is still short put the text out of it on the right*/
else {
txt_area.x1 = bar->indic_area.x2 + 5;
txt_area.x2 = txt_area.x1 + txt_size.x - 1;
dsc.color = lv_color_black();
}
txt_area.y1 = bar->indic_area.y1 + (lv_area_get_height(&bar->indic_area) - txt_size.y) / 2;
txt_area.y2 = txt_area.y1 + txt_size.y - 1;
const lv_area_t * clip_area = lv_event_get_param();
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)
{
static lv_style_t style_bg;
lv_style_init(&style_bg);
lv_style_set_content_ofs_y(&style_bg, -3);
lv_style_set_content_align(&style_bg, LV_ALIGN_OUT_TOP_MID);
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);
lv_obj_add_event_cb(bar, event_cb, NULL);
lv_obj_set_size(bar, 200, 20);
lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, bar);
lv_anim_set_values(&a, 0, 100);
lv_anim_set_exec_cb(&a, set_value);
lv_anim_set_time(&a, 2000);
lv_anim_set_playback_time(&a, 2000);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_start(&a);
}
#endif
//#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) {
// lv_bar_t * bar = (lv_bar_t *)obj;
//
// lv_draw_label_dsc_t dsc;
// lv_draw_label_dsc_init(&dsc);
// dsc.font = LV_FONT_DEFAULT;
//
// char buf[8];
// lv_snprintf(buf, sizeof(buf), "%d", lv_bar_get_value(obj));
//
// lv_point_t txt_size;
// lv_txt_get_size(&txt_size, buf, dsc.font, dsc.letter_space, dsc.line_space, LV_COORD_MAX, dsc.flag);
//
// lv_area_t txt_area;
// /*If the indicator is long enough put the text inside on the right*/
// if(lv_area_get_width(&bar->indic_area) > txt_size.x + 20) {
// txt_area.x2 = bar->indic_area.x2 - 5;
// txt_area.x1 = txt_area.x2 - txt_size.x + 1;
// dsc.color = lv_color_white();
// }
// /*If the indicator is still short put the text out of it on the right*/
// else {
// txt_area.x1 = bar->indic_area.x2 + 5;
// txt_area.x2 = txt_area.x1 + txt_size.x - 1;
// dsc.color = lv_color_black();
// }
//
// txt_area.y1 = bar->indic_area.y1 + (lv_area_get_height(&bar->indic_area) - txt_size.y) / 2;
// txt_area.y2 = txt_area.y1 + txt_size.y - 1;
//
// const lv_area_t * clip_area = lv_event_get_param();
// 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)
//{
// static lv_style_t style_bg;
// lv_style_init(&style_bg);
// lv_style_set_content_ofs_y(&style_bg, -3);
// lv_style_set_content_align(&style_bg, LV_ALIGN_OUT_TOP_MID);
//
// lv_obj_t * bar = lv_bar_create(lv_scr_act());
// lv_obj_add_event_cb(bar, event_cb, NULL);
// lv_obj_set_size(bar, 200, 20);
// lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);
//
// lv_anim_t a;
// lv_anim_init(&a);
// lv_anim_set_var(&a, bar);
// lv_anim_set_values(&a, 0, 100);
// lv_anim_set_exec_cb(&a, set_value);
// lv_anim_set_time(&a, 2000);
// lv_anim_set_playback_time(&a, 2000);
// lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
// lv_anim_start(&a);
//
//}
//
//#endif