Comments (7)
Interestingly, If I set the size to 200x19, the rendering result is correct. And I failed to reporduce this bug on another panel. So I reckon this issue might be due to this panel not supporting of odd coordinates, I'll do more test about this.
from lvgl.
Im trying to draw a progress bar using canvas, but I ended up with same results.
Here's my code.
template<typename Derived>
class BaseWidget
{
protected:
int32_t _w, _h;
lv_draw_buf_t *_draw_buf;
lv_obj_t * _canvas;
lv_layer_t _layer;
lv_draw_rect_dsc_t _dsc_bg;
public:
BaseWidget(lv_obj_t *parent, int32_t w, int32_t h)
{
_w = w;
_h = h;
_draw_buf = lv_draw_buf_create(w, h, LV_COLOR_FORMAT_RGB888, 0);
_canvas = lv_canvas_create(parent);
lv_canvas_set_draw_buf(_canvas, _draw_buf);
lv_canvas_init_layer(_canvas, &_layer);
lv_draw_rect_dsc_init(&_dsc_bg);
_dsc_bg.radius = 8;
}
virtual ~BaseWidget() {}
inline lv_obj_t *getCanvas()
{
return _canvas;
}
inline Derived& setBgColor(lv_color_t color, lv_opa_t opa)
{
_dsc_bg.bg_color = color;
_dsc_bg.bg_opa = opa;
return static_cast<Derived&>(*this);
}
inline Derived& clearBg()
{
lv_area_t coordsbg = {0, 0, _w, _h};
lv_draw_rect(&_layer, &_dsc_bg, &coordsbg);
return static_cast<Derived&>(*this);
}
};
class ProgressBarWidget : public BaseWidget<ProgressBarWidget>
{
private:
int32_t _min, _max, _range, _value;
lv_draw_rect_dsc_t _dsc;
public:
ProgressBarWidget(lv_obj_t *parent, int32_t w, int32_t h) : BaseWidget(parent, w, h)
{
lv_draw_rect_dsc_init(&_dsc);
_dsc.radius = 8;
}
~ProgressBarWidget() {}
inline ProgressBarWidget& setIndicatorColor(lv_color_t color, lv_opa_t opa)
{
_dsc.bg_color = color;
_dsc.bg_opa = opa;
return *this;
}
inline ProgressBarWidget& setRange(int min, int max)
{
_min = min;
_max = max;
_range = _max - _min;
return *this;
}
inline ProgressBarWidget& setValue(int value)
{
_value = value;
if (value < _min) {
value = _min;
}
else if (value > _max) {
value = _max;
}
int px = ((value - _min) / (float)_range) * _w;
lv_area_t coords = {0, 0, px, 50};
clearBg();
lv_draw_rect(&_layer, &_dsc, &coords);
lv_canvas_finish_layer(_canvas, &_layer);
lv_obj_invalidate(_canvas);
return *this;
}
inline ProgressBarWidget& setValueAnim(int value, int duration=800)
{
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_exec_cb(&a, [](void *obj, int32_t v) {
ProgressBarWidget *self = static_cast<ProgressBarWidget*>(obj);
self->setValue(v);
});
lv_anim_set_path_cb(&a, lv_anim_path_ease_out);
lv_anim_set_duration(&a, duration);
lv_anim_set_var(&a, this);
lv_anim_set_values(&a, _value, value);
lv_anim_set_repeat_count(&a, 0);
lv_anim_start(&a);
return *this;
}
};
ProgressBarWidget *pb = new ProgressBarWidget(lv_screen_active(), 200, 20);
pb->setBgColor(lv_color_make(0x00, 0x00, 0x00), LV_OPA_COVER)
.setIndicatorColor(lv_color_make(0x00, 0x00, 0xFF), LV_OPA_COVER)
.setRange(0, 100)
.setValue(50);
from lvgl.
I print out the refresh window at disp_flush()
:
printf("flush: %d %d %d %d\n", area->x1, area->y1, area->x2, area->y2);
And I got:
refresh: 0 0 200 20
The size of the canvas is 200x20, but the actual refresh area is xs:0, ys:0, xe:200, ye:20. I believe the correct window should be xs:0, ys:0, xe:199, ye:19.
from lvgl.
I print out the refresh window at
disp_flush()
:printf("flush: %d %d %d %d\n", area->x1, area->y1, area->x2, area->y2);
And I got:
refresh: 0 0 200 20
The size of the canvas is 200x20, but the actual refresh area is xs:0, ys:0, xe:200, ye:20. I believe the correct window should be xs:0, ys:0, xe:199, ye:19.
Oh, I still want to find the answer to this problem.
from lvgl.
Some display controllers require the x/y coordinates of the window area to be even or odd. Please check it in the data sheet.
If really this is the case you can add an event to the display like this, and adjust the coordinates as needed:
static void event_cb(lv_event_t * e)
{
lv_area_t * a = lv_event_get_param(e);
/*Modify the area to be invalidated*/
a->x1 = a->x1 & (~0&1); /*Make x1 even*/
}
lv_display_add_event_cb(disp, event_cb, LV_EVENT_INVALIDATE_AREA, NULL);
from lvgl.
Some display controllers require the x/y coordinates of the window area to be even or odd. Please check it in the data sheet.
If really this is the case you can add an event to the display like this, and adjust the coordinates as needed:
static void event_cb(lv_event_t * e) { lv_area_t * a = lv_event_get_param(e); /*Modify the area to be invalidated*/ a->x1 = a->x1 & (~0&1); /*Make x1 even*/ } lv_display_add_event_cb(disp, event_cb, LV_EVENT_INVALIDATE_AREA, NULL);
Thanks, I'll check that. And I wonder the answer about refresh window issue, shouldn't the window coordinates be x, y, w-1, h-1?
from lvgl.
Usually there is only an even or odd requirement. E.g. if x2 is 42 it should be change to 43 (odd). Or if y1 is 13 it needs to be 12 (even). But the datasheet will tell the exact requirements.
from lvgl.
Related Issues (20)
- get_x_aligned returns wrong value in case of percentage unit HOT 6
- STM32 Baremetal application only Renders to part of the screen HOT 5
- Change TileView Scroll animation speed HOT 3
- why the picture pixel blinking when running lvgl demo HOT 1
- Number and logic buttons in physical buttons
- Bengali string display abnormal using freetype lib HOT 2
- Cannot play custom gif in v9.1 HOT 6
- lvgl draws artefacts after button click HOT 4
- Could provide a font convert tool by c++? HOT 2
- Failing docs build HOT 16
- Grid layout style `grid_column_align` seems to have no effect HOT 7
- Linux DRM display mode locks up by default due to missing lv_tick_set_cb HOT 1
- discussion about C++ code in LVGL HOT 6
- lv_api_map_v8.h has no consideration for things that are enabled/disabled
- Buggy Demos in 9.x HOT 3
- tiny_ttf ignores cache_size in lv_tiny_ttf_create_file_ex function HOT 1
- Play lottie example HOT 8
- More color depths HOT 3
- 9.1 Input Device Documentation HOT 6
- macOS buiold failure
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lvgl.