I am using Master (latest) version (dated: 17 Jan 2024). It may be v8.3. I am implementing LVGL control in WPF technology. I am trying to implement gradient effect for an object. As per LVGL documentation, I have possible it using 2 ways. In both ways, I can take max number of colours or gradient stops as 2. If I want to set it as more than 2, then I am not getting idea to implement it.
In 1st way, I have implemented below code:
__declspec(dllexport) void DrawGradient1(int width, int height, int fillColor1, int fillColor2)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_radius(&style, 5);
/*Make a gradient*/
lv_style_set_bg_opa(&style, LV_OPA_COVER);
static lv_grad_dsc_t grad;
grad.dir = LV_GRAD_DIR_VER;
grad.stops_count = 2;
grad.stops[0].color = lv_palette_main(LV_PALETTE_RED);
grad.stops[0].opa = LV_OPA_COVER;
grad.stops[1].color = lv_palette_main(LV_PALETTE_GREEN);
grad.stops[1].opa = LV_OPA_COVER;
/*Shift the gradient to the bottom*/
grad.stops[0].frac = 0;
grad.stops[1].frac = 144;
lv_style_set_bg_grad(&style, &grad);
/*Create an object with the new style*/
lv_obj_t* obj = lv_obj_create(lv_screen_active());
lv_obj_add_style(obj, &style, 0);
lv_obj_set_size(obj, width, height);
lv_obj_center(obj);
}
In 2nd way, I have implemented below code:
__declspec(dllexport) void DrawGradient2(int width, int height, int fillColor1, int fillColor2)
{
lv_obj_t* grad = lv_obj_create(lv_screen_active());
lv_obj_set_size(grad, width, height);
lv_obj_center(grad);
lv_obj_set_style_bg_color(grad, lv_color_hex(fillColor1), 0);
lv_obj_set_style_bg_grad_color(grad, lv_color_hex(fillColor2), 0);
lv_obj_set_style_bg_grad_dir(grad, LV_GRAD_DIR_VER, 0);
}