Draw line on canvas does not work?


I’ve following code, but the line is not drawed, can only see the background of the canvas (red), and a small green rectangle.
Why I can’t see the line?

I’m using lvgl version 8.3.2

Thank you

	//static lv_color_t buf_screen_1_canvas_1[100*100*4];
	static lv_color_t buf_screen_1_canvas_1[LV_CANVAS_BUF_SIZE_INDEXED_1BIT(100, 100)];
	//lv_canvas_set_buffer(ui->screen_1_canvas_1, buf_screen_1_canvas_1, 100, 100, LV_IMG_CF_TRUE_COLOR_ALPHA);
	lv_canvas_set_buffer(ui->screen_1_canvas_1, buf_screen_1_canvas_1, 100, 100, LV_IMG_CF_INDEXED_1BIT);
    lv_canvas_set_palette(ui->screen_1_canvas_1, 0, LV_COLOR_CHROMA_KEY);
    lv_canvas_set_palette(ui->screen_1_canvas_1, 1, lv_palette_main(LV_PALETTE_RED));

    /*Create colors with the indices of the palette*/
    lv_color_t c0;
    lv_color_t c1;

    c0.full = 0;
    c1.full = 1;

	//lv_canvas_fill_bg(ui->screen_1_canvas_1, lv_color_make(0xff, 0xff, 0xff), 255);
    lv_canvas_fill_bg(ui->screen_1_canvas_1, c1, LV_OPA_COVER);

    /*Create hole on the canvas*/
    uint32_t x;
    uint32_t y;
    for(y = 10; y < 30; y++) {
        for(x = 5; x < 20; x++) {
            lv_canvas_set_px_color(ui->screen_1_canvas_1, x, y, c0);

    lv_draw_line_dsc_t draw_line_dsc;
    lv_draw_line_dsc_init(&draw_line_dsc); // Linienstil initialisieren
    draw_line_dsc.color = c0; // Linienfarbe setzen
    draw_line_dsc.width = 8;
    //lv_point_t points[] = {last_point, current_point};
    //lv_point_t points[] = {{10, 20}, {30, 40}};
    lv_point_t points[2] = {{20, 50}, {80, 50}};
    lv_canvas_draw_line(ui->screen_1_canvas_1, points, 2, &draw_line_dsc); // draw line with style

lv_canvas_draw_line does not work with LV_CANVAS_BUF_SIZE_INDEXED_xBIT

@epikao , I ran into the same confusion for a bit. It wasn’t quite clear to me what things were supported in the canvas and what things were not. I wound up wrapping up the canvas concept in two C++ classes lvppCanvasFullColor and lvppCanvasIndexed which handle these big ‘switches’ between the two modes. The Indexed version of the canvas class does allow for drawing lines and rectangles, but in a less feature rich manner than the full color support - at least today.

These are part of a library that I just made public yesterday. If you’re interested in a C++ wrapper for canvas as well as much of the LVGL library, have a look at my My Project intro topic here on the forums or go directly to the Github project at LVGLPlusPlus and its associated Doxygen Docs for LVGLPlusPlus

Happy to hear feedback if there’s no flame throwers involved. :stuck_out_tongue_winking_eye: