Using lv_line_set_points() with a line width>1 doesn't seem to draw to the right/bottom edge

Description

I’d like to draw a horizontal line from the far left edge (0) to the right edge (SCREEN_WIDTH-1), but when I do this with a line which has more than a pixel width of 1 pixel in its associated style, I wind up with a display that gets a horizontal scroll-bar added to it at the bottom. The same thing happens for a vertical line.

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

I’m using a Mac with the simulator and also an ESP32 with a TFT display being driven by TFT_eSPI.

What LVGL version are you using?

I’m using LVGL 8.3

What do you want to achieve?

As said above - I’d like to be able to draw a line of width 4 or 5 pixels and draw it all the way from the left to the right or down the the bottom edge fully. But it seems the width of the line being anything but ‘1’ prevents drawing all the way to the edge.

What have you tried so far?

  • I’ve tried this on both the simulator and on an ESP32 device - same results.
  • If the line is width=1, everything is fine.
  • If the line is width=2, I can draw to WIDTH-2 without getting a scrollbar, but not to WIDTH-1
  • I’ve tested this out to width=5 and the same notion applies - I can draw to WIDTH-4 in this case or HEIGHT-4 but not to “-3”, “-2”, nor “WIDTH-1” without getting scroll bars added.

Code to reproduce

I’ve distilled the issue down by going back to the original line example code at Line (lv_line) — LVGL documentation and only modifying a bit of that code to demonstrate the issue. Each change I made has a // mod: in the comment.

The code block(s) should be formatted like:

/*You code here*/
void lv_example_line_edge(void)
{
    /*Create an array for the points of the line*/
    static lv_point_t line_points[2] = {{0,120}, {SCREEN_WIDTH-1,120}};  // mod: changed points
    lv_coord_t width = 4;   // mod: setup width to easily change

    /*Create style*/
    static lv_style_t style_line;
    lv_style_init(&style_line);
    lv_style_set_line_width(&style_line, width); // mod: using 'width' instead of 8
    lv_style_set_line_color(&style_line, lv_palette_main(LV_PALETTE_BLUE));
    lv_style_set_line_rounded(&style_line, false);

    /*Create a line and apply the new style*/
    lv_obj_t * line1;
//    line1 = lv_line_create(lv_scr_act()); // mod: here's the original
    line1 = lv_line_create(pScreenSplash->GetScreen()); // mod: using my own parent screen to draw on.
    lv_line_set_points(line1, line_points, 2);     /*Set the points*/ // mod: only using 2 points.
    lv_obj_add_style(line1, &style_line, 0);
//    lv_obj_center(line1); // mod: I do not want my line centered.
}

Screenshot and/or video

If you run the above (use lv_line_create(lv_scr_act());) if you’re really running it) – and you use width=4, you’ll get the following screen effects of the horizontal scroll bar at the bottom:


And if, instead, you use a width=1; instead, you’ll get the smaller thickness but you’ll also NOT see a scrollbar added to the display.

Lastly, if I bring the width back to 4 but I reduce the X value of the second point to be X=SCREEN_WIDTH-4, you can see the line stops short of the right side (of course), but the scroll bar doesn’t show up anymore. Sigh … I’m a new user so it only allows me to show 2 media attachments. Trust me? :slight_smile:

Here’s the 3rd image I couldn’t post in the original which shows a shorter SCREEN_WIDTH-4 line which is width=4; and showing there’s no scroll bars.

Hi @bobwolff68 ,

Personally I would suggest disabling the scrolling if you want to draw this way, as the properties of the line will alter the behaviour of the scroll bars because of the way LVGL works.

You should be able to use this call somewhere before you draw the line:

	lv_obj_clear_flag(pScreenSplash->GetScreen(), LV_OBJ_FLAG_SCROLLABLE);

If you need the drawing to be bigger than the screen you might also consider creating an lv_obj_t *container which is bigger than your screen, remove the scrollable flag from the container so it won’t create scrollbars when you draw close to the edges and your drawing will behave correctly, but you can still scroll the container around with the screen scrollbars. I hope that makes sense!

Cheers,

Pete

@pete-pjb - thanks a bunch for this. This is a perfect solution for me. I hadn’t recognized that ability. Still coming up to speed but I sure do love this library.

–bob

1 Like

No worries Bob, yes I agree it is a fantastic library I think @kisvegabor has done a great job!

It does take a little while to get to grips with all the functionality. I been using it for a few years now and I am still finding things out!

Glad I could help. :blush:

2 Likes