Trying to display multiple + signs on CYD

Description

Need Arduino function to generate “+” signs on display

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

Cheap Yellow Display, ESP32-2432S028, Arduino IDE 2.3.2

What LVGL version are you using?

9.1

What do you want to achieve?

I’m attempting to write an Arduino function that can be called multiple times with coordinates and size of a “+” sign, and will store the various horizontal and vertical components of the “+” signs in an array of line objects.

What have you tried so far?

I’ve written one version of the function that creates six separate line objects (three for vertical lines, three for horizontal lines) for three “+” signs. That seems to work. Now I’m hoping to create an Arduino function I can call that will create an array of line objects for four (as a starting point) “+” signs.

Code to reproduce

void lv_draw_cross(int cross_nr, lv_point_precise_t center, long int len_pixels) {
    static lv_obj_t *lines[8];
    lv_point_precise_t point, h_line[2], v_line[2];

    // Calculate points for horizontal line
    point.x = center.x - len_pixels / 2;
    point.y = center.y;
    h_line[0] = point;
    point.x = center.x + len_pixels / 2;
    h_line[1] = point;

    // Calculate points for vertical line
    point.x = center.x;
    point.y = center.y - len_pixels / 2;
    v_line[0] = point;
    point.y = center.y + len_pixels / 2;
    v_line[1] = point;

    // Create style
    static lv_style_t style_line;
    lv_style_init(&style_line);
    lv_style_set_line_width(&style_line, 2);
    lv_style_set_line_color(&style_line, lv_palette_main(LV_PALETTE_BLUE));
    lv_style_set_line_rounded(&style_line, true);

    // Create and style horizontal line
    lines[cross_nr * 2] = lv_line_create(lv_scr_act());
    lv_line_set_points(lines[cross_nr * 2], h_line, 2);
    lv_obj_add_style(lines[cross_nr * 2], &style_line, 0);

    // Create and style vertical line
    lines[cross_nr * 2 + 1] = lv_line_create(lv_scr_act());
    lv_line_set_points(lines[cross_nr * 2 + 1], v_line, 2);
    lv_obj_add_style(lines[cross_nr * 2 + 1], &style_line, 0);
}

I call the function like so:

  lv_point_precise_t center1 = {80, 60};
  lv_point_precise_t center2 = {240, 60};
  lv_point_precise_t center3 = {80, 160};
  lv_point_precise_t center4 = {240, 160};

  lv_draw_cross(0, center1, 20);
  lv_draw_cross(1, center2, 40);
  lv_draw_cross(2, center3, 40);
  lv_draw_cross(2, center3, 20);

Screenshot and/or video

This is what I get.