App:Library:LVGL:docs:Overview:Drawing
https://docs.lvgl.io/8.2/overview/drawing.html
Drawing
英文 | 自動翻訳 |
---|---|
With LVGL, you don't need to draw anything manually. Just create objects (like buttons, labels, arc, etc.), move and change them, and LVGL will refresh and redraw what is required. However, it can be useful to have a basic understanding of how drawing happens in LVGL to add customization, make it easier to find bugs or just out of curiosity. The basic concept is to not draw directly onto the display but rather to first draw on an internal draw buffer. When a drawing (rendering) is ready that buffer is copied to the display.
LVGL will simply render in "tiles" that fit into the given draw buffer. This approach has two main advantages compared to directly drawing to the display:
|
LVGLを使えば、何も手動で描く必要はありません。
オブジェクト(ボタン、ラベル、円弧など)を作成し、移動、変更するだけで、LVGLは必要なものをリフレッシュして再描画します。 しかし、LVGLでどのように描画が行われるかを基本的に理解しておくことは、カスタマイズの追加やバグの発見を容易にするため、あるいは単なる好奇心で、役に立つことがあるのです。 基本的なコンセプトは、ディスプレイに直接描画するのではなく、まず内部のドローバッファに描画することです。 描画(レンダリング)の準備ができると、そのバッファがディスプレイにコピーされます。
LVGLは、与えられたドローバッファに収まる「タイル」で単純にレンダリングします。 この方法は、ディスプレイへの直接描画と比較して、主に2つの利点があります。
|
Mechanism of screen refreshing
英文 | 自動翻訳 |
---|---|
Be sure to get familiar with the Buffering modes of LVGL first. LVGL refreshes the screen in the following steps:
When an area is redrawn the library searches the top-most object which covers that area and starts drawing from that object. For example, if a button's label has changed, the library will see that it's enough to draw the button under the text and it's not necessary to redraw the display under the rest of the button too. The difference between buffering modes regarding the drawing mechanism is the following:
|
まず,LVGL の Buffering モードに慣れるようにしてください.
LVGLは以下の手順で画面を更新しています。
When an area is redrawn the library searches the top-most object which covers that area and starts drawing from that object. For example, if a button's label has changed, the library will see that it's enough to draw the button under the text and it's not necessary to redraw the display under the rest of the button too. The difference between buffering modes regarding the drawing mechanism is the following:
|
Masking
英文 | 自動翻訳 |
---|---|
Masking is the basic concept of LVGL's draw engine. To use LVGL it's not required to know about the mechanisms described here but you might find interesting to know how drawing works under hood. Knowing about masking comes in handy if you want to customize drawing. To learn about masking let's see the steps of drawing first. LVGL performs the following steps to render any shape, image or text. It can be considered as a drawing pipeline.
LVGL has the following built-in mask types which can be calculated and applied real-time:
Masks are used to create almost every basic primitive:
|
Using masks
英文 | 自動翻訳 |
---|---|
Every mask type has a related parameter structure to describe the mask's data. The following parameter types exist:
A parameter can be added and removed any number of times, but it needs to be freed when not required anymore.
|
Hook drawing
英文 | 自動翻訳 |
---|---|
Although widgets can be easily customized by styles there might be cases when something more custom is required. To ensure a great level of flexibility LVGL sends a lot of events during drawing with parameters that tell what LVGL is about to draw. Some fields of these parameters can be modified to draw something else or any custom drawing operations can be added manually. A good use case for this is the Button matrix widget. By default, its buttons can be styled in different states, but you can't style the buttons one by one. However, an event is sent for every button and you can, for example, tell LVGL to use different colors on a specific button or to manually draw an image on some buttons. Each of these events is described in detail below. |
Main drawing
英文 | 自動翻訳 |
---|---|
These events are related to the actual drawing of an object. E.g. the drawing of buttons, texts, etc. happens here.
The clip area is required in draw functions to make them draw only on a limited area. |
LV_EVENT_DRAW_MAIN_BEGIN
英文 | 自動翻訳 |
---|---|
Sent before starting to draw an object. This is a good place to add masks manually. E.g. add a line mask that "removes" the right side of an object. |
LV_EVENT_DRAW_MAIN
英文 | 自動翻訳 |
---|---|
The actual drawing of an object happens in this event. E.g. a rectangle for a button is drawn here. First, the widgets' internal events are called to perform drawing and after that you can draw anything on top of them. For example you can add a custom text or an image. |
LV_EVENT_DRAW_MAIN_END
英文 | 自動翻訳 |
---|---|
Called when the main drawing is finished. You can draw anything here as well and it's also a good place to remove any masks created in |
Post drawing
英文 | 自動翻訳 |
---|---|
Post drawing events are called when all the children of an object are drawn. For example LVGL use the post drawing phase to draw scrollbars because they should be above all of the children.
|
LV_EVENT_DRAW_POST_BEGIN
英文 | 自動翻訳 |
---|---|
Sent before starting the post draw phase. Masks can be added here too to mask out the post drawn content. |
LV_EVENT_DRAW_POST
英文 | 自動翻訳 |
---|---|
The actual drawing should happen here. |
LV_EVENT_DRAW_POST_END
英文 | 自動翻訳 |
---|---|
Called when post drawing has finished. If masks were not removed in |
Part drawing
英文 | 自動翻訳 |
---|---|
When LVGL draws a part of an object (e.g. a slider's indicator, a table's cell or a button matrix's button) it sends events before and after drawing that part with some context of the drawing.
In these events an Not all fields are set for every part and widget.
// Always set const lv_area_t * clip_area; // The current clip area, required if you need to draw something in the event uint32_t part; // The current part for which the event is sent uint32_t id; // The index of the part. E.g. a button's index on button matrix or table cell index. // Draw desciptors, set only if related lv_draw_rect_dsc_t * rect_dsc; // A draw descriptor that can be modified to changed what LVGL will draw. Set only for rectangle-like parts lv_draw_label_dsc_t * label_dsc; // A draw descriptor that can be modified to changed what LVGL will draw. Set only for text-like parts lv_draw_line_dsc_t * line_dsc; // A draw descriptor that can be modified to changed what LVGL will draw. Set only for line-like parts lv_draw_img_dsc_t * img_dsc; // A draw descriptor that can be modified to changed what LVGL will draw. Set only for image-like parts lv_draw_arc_dsc_t * arc_dsc; // A draw descriptor that can be modified to changed what LVGL will draw. Set only for arc-like parts // Other parameters lv_area_t * draw_area; // The area of the part being drawn const lv_point_t * p1; // A point calculated during drawing. E.g. a point of a chart or the center of an arc. const lv_point_t * p2; // A point calculated during drawing. E.g. a point of a chart. char text[16]; // A text calculated during drawing. Can be modified. E.g. tick labels on a chart axis. lv_coord_t radius; // E.g. the radius of an arc (not the corner radius). int32_t value; // A value calculated during drawing. E.g. Chart's tick line value. const void * sub_part_ptr; // A pointer the identifies something in the part. E.g. chart series.
|
LV_EVENT_DRAW_PART_BEGIN
英文 | 自動翻訳 |
---|---|
Start the drawing of a part. This is a good place to modify the draw descriptors (e.g. |
LV_EVENT_DRAW_PART_END
英文 | 自動翻訳 |
---|---|
Finish the drawing of a part. This is a good place to draw extra content on the part or remove masks added in |
Others
LV_EVENT_COVER_CHECK
英文 | 自動翻訳 |
---|---|
This event is used to check whether an object fully covers an area or not.
Here are some reasons why an object would be unable to fully cover an area:
In short if for any reason the area below an object is visible than the object doesn't cover that area. Before sending this event LVGL checks if at least the widget's coordinates fully cover the area or not. If not the event is not called.
The existing properties known by a widget are handled in its internal events. E.g. if a widget has > 0 radius it might not cover an area, but you need to handle |
LV_EVENT_REFR_EXT_DRAW_SIZE
英文 | 自動翻訳 |
---|---|
If you need to draw outside a widget, LVGL needs to know about it to provide extra space for drawing. Let's say you create an event which writes the current value of a slider above its knob. In this case LVGL needs to know that the slider's draw area should be larger with the size required for the text. You can simply set the required draw area with |