How to set cells height in a table

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

  1. how to set cells height in a table? It seems different from V6.0.2, I read the docs and try to add the padding style to the table, it seems not work.
  2. By the way, in V6.0.2, there is a declare LV_TABLE_COL_MAX in lv_conf.h, in V8.0.1, is still has this declare and the limit of table column num?

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

What LVGL version are you using?

8.0.1

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:

static void ta_event_cb(lv_event_t * e)
    {
        lv_event_code_t code = lv_event_get_code(e);
        lv_obj_t * ta = lv_event_get_target(e);
        if(code == LV_EVENT_CLICKED || code == LV_EVENT_FOCUSED) {
            /*Focus on the clicked text area*/
            if(g_keyboard != NULL)
                {
                lv_obj_clear_flag(g_keyboard, LV_OBJ_FLAG_HIDDEN);
                    lv_keyboard_set_textarea(g_keyboard, ta);
                }
        }

        else if(code == LV_EVENT_READY) {
            LV_LOG_USER("Ready, current text: %s", lv_textarea_get_text(ta));
        }
    }

static void KeyboardEventCB(lv_event_t* event)
{
//    lv_keyboard_def_event_cb(event);
//
    lv_event_code_t code = lv_event_get_code(event);
//
//    lv_obj_t* ta_of_kb = lv_keyboard_get_textarea(g_keyboard);
//
    if(code == LV_EVENT_CANCEL)
    {
//        lv_textarea_t * ta = (lv_textarea_t *)ta_of_kb;
//        ta->cursor.show = 0;
        lv_obj_add_flag(g_keyboard, LV_OBJ_FLAG_HIDDEN);
    }
}

void CreateKeyboard(lv_obj_t* parent, lv_coord_t w, lv_coord_t h)
{
    g_keyboard = lv_keyboard_create(parent);

   
    lv_obj_set_size(g_keyboard, w, h);
    lv_obj_align_to(g_keyboard, parent, LV_ALIGN_BOTTOM_RIGHT, 0, 0);
  
//    lv_obj_add_event_cb(g_keyboard, KeyboardEventCB, LV_EVENT_CANCEL, NULL);

  
//    lv_obj_add_flag(g_keyboard, LV_OBJ_FLAG_HIDDEN);
}


int main()
{
    CreateKeyboard(lv_scr_act(), 940, 150);

    lv_obj_clear_flag(g_keyboard, LV_OBJ_FLAG_HIDDEN);

    lv_obj_t * text_ta = lv_textarea_create(lv_scr_act());
    lv_textarea_set_one_line(text_ta, true);
    lv_textarea_set_password_mode(text_ta, false);
    lv_obj_set_width(text_ta, lv_pct(40));
    lv_obj_add_event_cb(text_ta, ta_event_cb, LV_EVENT_ALL, NULL);
    lv_obj_align_to(text_ta, NULL, LV_ALIGN_TOP_LEFT, 0, 60);

    lv_obj_t * text_ta1 = lv_textarea_create(lv_scr_act());
    lv_textarea_set_one_line(text_ta1, true);
    lv_textarea_set_password_mode(text_ta1, false);
    lv_obj_set_width(text_ta1, lv_pct(40));
    lv_obj_add_event_cb(text_ta1, ta_event_cb, LV_EVENT_ALL, NULL);
    lv_obj_align_to(text_ta1, NULL, LV_ALIGN_TOP_RIGHT, 0, 60);
}

Screenshot and/or video

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

You need to set the vertical padding of the cells. E.g.

lv_obj_set_style_pad_ver(table, 50, LV_PART_ITEMS);

It’s not required. In v8 it’s managed dynamically.

1 Like

thanks, it work well by setting the vertical padding.

By the way, how to disable the style when I clicked one cell?

A little suggestion fot table widget, I think for most application scenarios, it just uses table to show datas, so table widget should be easy for developers. For exmaple, when I set the vertical padding for cells, the table should adjust the total height also. In lvgl, it juest the sum of cells hight, but never changeed the background height. Also, it will be better to show boundary between cells.

If you set the height of the table to LV_SIZE_CONTENT the height will be set to involve all cells.

lv_obj_set_style_border_side(table, LV_BORDER_SIDE_FULL, LV_PART_ITEMS);

should do the job.


Meanwhile, I pushed a related fix to master.