Where button styles like LV_BTN_STYLE_REL are defined?

Description

In issue number #119 LV_BTN_STYLE_REL is given as a way to create transparent button style. However compiler can’t find the definition for this constant (also mentioned in lv_obj.c line 3271)

What MCU/Processor/Board and compiler are you using?

simulator and STM32F769I-DISCO

What LVGL version are you using?

7.5.0

What do you want to achieve?

A clickable image as described in issue #119

What have you tried so far?

tryed to compile the example from issue #119

Code to reproduce

   lv_obj_t * btn1 =  lv_btn_create(lv_scr_act(), NULL);
    lv_btn_set_fit(btn1, true, true);                        /*Automatically increase the size to involve all children (now only the image)*/
    lv_btn_set_style(btn1, LV_BTN_STYLE_REL, &lv_style_transp_tight);   /*Transparent style for released button*/
    lv_btn_set_style(btn1, LV_BTN_STYLE_PR, &lv_style_transp_tight);   /*Transparent style for pressed button*/
    lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK, lpr_test);
    lv_obj_t * img = lv_img_create(btn1, NULL);                         /*Create the image on 'btn1'*/
    lv_obj_set_click(img, false);                                  /*Don't let to click to the image (click the background button instead)*/
   /*...and finally set a file for the image...*/

Hi
I don’t know where is issue #119, (which would be better to be linked to.)
But the problem is, you are using codes compatible with ver 6. So otherwise use the LVGL ver 6, or better use example codes for ver 7.

Hi all,

For reference:

The issue is here. This as @Ali_Rostami has said is really old version 5.x.

Kind Regards,

Pete

1 Like

Can you direct me to an example of producing a clickable image in version 7+ ?
Thanks

Hi @icodk ,

I think an update to the example you referenced would look something like this for V7+:

    lv_obj_t * btn1 =  lv_btn_create(lv_scr_act(), NULL);
    lv_btn_set_fit(btn1, LV_FIT_TIGHT);                        /*Automatically increase the size to involve all children (now only the image)*/
    lv_obj_set_pos(btn1, 20, 20);
    lv_obj_set_style_local_bg_opa(btn1, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); 
    lv_obj_set_style_local_bg_opa(btn1, LV_BTN_PART_MAIN, LV_STATE_PRESSED, LV_OPA_TRANSP);
    lv_obj_t * img = lv_img_create(btn1, NULL);                         /*Create the image on 'btn1'*/
    lv_obj_set_click(img, false);                                  /*Don't let to click to the image (click the background button instead)*/
    lv_img_set_src(img, LV_SYMBOL_OK "Accept");

Kind Regards,

Pete

Managed to do it with the following code:

LV_IMG_DECLARE(logo);

	/*Darken the button when pressed*/
	
	static lv_style_t style;
	lv_style_init(&style);
	lv_style_set_image_recolor_opa(&style, LV_STATE_PRESSED, LV_OPA_30);
	/*Create an Image button*/
	lv_obj_t * imgbtn1 = lv_imgbtn_create(lv_scr_act(), NULL);
	lv_imgbtn_set_src(imgbtn1, LV_BTN_STATE_RELEASED, &logo);
	lv_imgbtn_set_src(imgbtn1, LV_BTN_STATE_PRESSED, &logo);
	
	lv_obj_add_style(imgbtn1, LV_IMGBTN_PART_MAIN, &style);
	lv_obj_align(imgbtn1, NULL, LV_ALIGN_CENTER, 0, -40);
	
	lv_obj_set_event_cb(imgbtn1, event_handler_logo);

Many thanks

1 Like

Hi @icodk ,

Glad you achieved your goal.

Kind Regards,

Pete