Git Product home page Git Product logo

Comments (7)

icyqwq avatar icyqwq commented on July 2, 2024 1

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.

icyqwq avatar icyqwq commented on July 2, 2024

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.

icyqwq avatar icyqwq commented on July 2, 2024

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.

icyqwq avatar icyqwq commented on July 2, 2024

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.

kisvegabor avatar kisvegabor commented on July 2, 2024

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.

icyqwq avatar icyqwq commented on July 2, 2024

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.

kisvegabor avatar kisvegabor commented on July 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.