Create a dashed line

So, I have been thinking about this problem for about a day and im having a little trouble coming up with a good solution.

There are 2 solutions that I can see:

  1. Create an lv_obj_t line object for each dash (This is “easy”, but seems terrible tbh)
  2. Draw the lines using the draw ctx and drawing them directly circumventing lv objects, I suppose if I really wanted to be special I could create a widget lv_fancy_line or some such

Am I missing a potential solution? I coded out 1 and I just hate the solution, waste of memory.

Well, Ill be damned…

In writing a base object for drawing this, im 90% through it and I see I have been wasting my time.

lv_coord_t dash_width;
lv_coord_t dash_gap;

typedef struct {
    lv_color_t color;
    lv_coord_t width;
    lv_coord_t dash_width; 
    lv_coord_t dash_gap;
    lv_opa_t opa;
    lv_blend_mode_t blend_mode  : 2;
    uint8_t round_start : 1;
    uint8_t round_end   : 1;
    uint8_t raw_end     : 1;    /*Do not bother with perpendicular line ending if it's not visible for any reason*/
} lv_draw_line_dsc_t;

le sigh… Well it was a good walk thru the internals of LVGL. :slight_smile:

I really should make a post that entails Ron’s things he learned the hard way


Hi, @rohmer !

I’m an a master C programmer, but relatively new to LVGL. I have created my own LVGL widget and in that widget in the widget_event for event LV_EVENT_DRAW_MAIN, I prepare a drawing descriptor with a part descriptor attached particular to the part, and then call

lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc);

so that client code can hook the event and modify the drawing characteristics before it actually begins. However, for a line, the LV_EVENT_DRAW_MAIN event does not call lv_event_send() with with the lv_draw_line_dsc_t object it creates. Once the line_dsc is prepared, it only calls lv_draw_line(), which does not seem to call lv_event_send() at all – so that I can hook the event and modify the dash_width and dash_gap fields of the lv_draw_line_dsc_t it passes…

So I have been spinning my wheels here for about an hour trying to figure out how you created a dashed line. Can you help me understand what I am missing please? (I am using release/8.3 branch.)

*laughing at self* Found it – buried in STYLES. It would have helped if the v8.3 documentation for LINE covered the line style properties. Ah well.