How to disable some special objects like ddlist/textarea click?

Description

we can use lv_obj_set_click() to set btns unclick, but I found it doesn’t work when object is ddlist or textarea. I want to set ddlist can’t open when I touch it.

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

What do you want to achieve?

What have you tried so far?

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

For lv_ddlist, if you want to use lv_obj_set_click(ddlist, false)
add the following code to your code.

static lv_signal_cb_t anc_ddlist_scrl_signal;
static lv_res_t ddlist_ext_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);

lv_obj_t*  my_ddlist_create(lv_obj_t* par, lv_obj_t* copy) {
  lv_obj_t* ddlist = lv_ddlist_create(par, copy);
  lv_obj_t* ddlist_scrl = lv_page_get_scrl(ddlist);
  anc_ddlist_scrl_signal = lv_obj_get_signal_cb(ddlist_scrl);
  lv_obj_set_signal_cb(ddlist_scrl, ddlist_ext_scrl_signal);
  return ddlist;
}

static lv_res_t ddlist_ext_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
{
  lv_res_t res = LV_RES_OK;
  if ( sign != LV_SIGNAL_RELEASED || (sign == LV_SIGNAL_RELEASED && lv_obj_get_click(lv_obj_get_parent(scrl)) ) ) {
    res = anc_ddlist_scrl_signal(scrl, sign, param);
  }
  return res;
}

Usage

void lv_example_ddlist(void)
{
  /*Create a drop down list*/
  lv_obj_t * ddlist = my_ddlist_create(lv_scr_act(), NULL);
  lv_ddlist_set_options(ddlist, "Apple\n"
                                "Banana\n"
                                "Orange\n"
                                "Melon\n"
                                "Grape\n"
                                "Raspberry");

  lv_ddlist_set_fix_width(ddlist, 150);
  lv_ddlist_set_draw_arrow(ddlist, true);
  lv_obj_align(ddlist, NULL, LV_ALIGN_IN_TOP_MID, 0, 20);

  lv_obj_set_click(ddlist, false);  // ---> disable click for ddlist
}

Fot lv_ta use the following code.

static lv_signal_cb_t anc_ta_scrl_signal;
static lv_res_t ta_ext_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param);

lv_obj_t*  my_ta_create(lv_obj_t* par, lv_obj_t* copy) {
  lv_obj_t* ta = lv_ta_create(par, copy);
  lv_obj_t* ta_scrl = lv_page_get_scrl(ta);
  anc_ta_scrl_signal = lv_obj_get_signal_cb(ta_scrl);
  lv_obj_set_signal_cb(ta_scrl, ta_ext_scrl_signal);
  return ta;
}

static lv_res_t ta_ext_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param)
{
  lv_res_t res = LV_RES_OK;
  if(sign == LV_SIGNAL_PRESSING || sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_PRESS_LOST ||
     sign == LV_SIGNAL_RELEASED)
  {
    if(lv_obj_get_click(lv_obj_get_parent(scrl)))
      res = anc_ta_scrl_signal(scrl, sign, param);
  }else{
    res = anc_ta_scrl_signal(scrl, sign, param);
  }
  return res;
}

Usage

void lv_example_ta(void)
{
  lv_obj_t* ta1 = my_ta_create(lv_scr_act(), NULL);
  lv_obj_set_size(ta1, 200, 100);
  lv_obj_align(ta1, NULL, LV_ALIGN_CENTER, 0, 0);
  lv_ta_set_cursor_type(ta1, LV_CURSOR_BLOCK);
  lv_ta_set_text(ta1, "A text in a Text Area");    /*Set an initial text*/

  lv_obj_set_click(ta1, false);  // ---> disable click for textarea
}

Are you using the latest version of LittlevGL? lv_ddlist should work with lv_obj_set_click; this was fixed here.

my version is 6.0.1,

Can you explain how it work? It confused me.

That explains why it’s not working. You’ll have to either update to 6.1, backport this patch, or use @TridentTD’s fix if you want the feature.