Description
I’m new to LVGL and I’m trying to draw a button with a particular behavior when pressed.
What MCU/Processor/Board and compiler are you using?
SDL
What LVGL version are you using?
v8.2
What do you want to achieve?
I want to have a button with a text and a subtext. Once the button is pressed, the text and the subtext must not have the same color.
What have you tried so far?
Code to reproduce
static lv_obj_t * page = lv_obj_create(lv_scr_act());
lv_obj_set_size(page, lv_pct(100), lv_pct(100));
const lv_color_t red = lv_color_hex(0xff0000);
const lv_color_t green = lv_color_hex(0x00ff00);
const lv_color_t blue = lv_color_hex(0x0000ff);
lv_style_t style1;
lv_style_init(&style1);
lv_style_set_bg_opa(&style1, LV_OPA_COVER);
lv_style_set_bg_color(&style1, red);
lv_style_set_pad_all(&style1, 5);
lv_style_t style2;
lv_style_init(&style2);
lv_style_set_bg_opa(&style2, LV_OPA_COVER);
lv_style_set_bg_color(&style2, green);
lv_style_t style3;
lv_style_init(&style3);
lv_style_set_text_color(&style3, green);
lv_style_t style4;
lv_style_init(&style4);
lv_style_set_text_color(&style4, red);
lv_style_t style5;
lv_style_init(&style5);
lv_style_set_text_color(&style5, green);
lv_style_t style6;
lv_style_init(&style6);
lv_style_set_text_color(&style6, blue);
static lv_obj_t * btn1 = lv_btn_create(page);
static lv_obj_t * label1 = lv_label_create(btn1);
static lv_obj_t * label2 = lv_label_create(btn1);
lv_obj_remove_style_all(btn1);
lv_obj_add_style(btn1, &style1, LV_STATE_DEFAULT);
lv_obj_add_style(btn1, &style2, LV_STATE_PRESSED);
lv_obj_remove_style_all(label1);
lv_obj_add_style(label1, &style3, LV_STATE_DEFAULT);
lv_obj_add_style(label1, &style4, LV_STATE_PRESSED);
lv_obj_remove_style_all(label2);
lv_obj_add_style(label2, &style5, LV_STATE_DEFAULT);
lv_obj_add_style(label2, &style6, LV_STATE_PRESSED);
lv_label_set_text(label1, "Title");
lv_label_set_text(label2, "Subtitle");
lv_obj_center(btn1);
lv_obj_align(label1, LV_ALIGN_CENTER, 0, -5);
lv_obj_align_to(label2, label1, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
lv_obj_set_size(btn1, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
Screenshot and/or video
LV_STATE_DEFAULT:
LV_STATE_PRESSED: