How to set opacity of meter arc?

Description

As title says.

What MCU/Processor/Board and compiler are you using?

ATSAM4S4A

What LVGL version are you using?

v8.3

What do you want to achieve?

I am struggling to set the opacity of an arc from the meter widget.

What have you tried so far?

I have tried the following lines so far, with no result.

lv_obj_set_style_arc_opa(meter_obj, value, LV_PART_ITEMS);
lv_obj_set_style_opa(meter_obj, value, LV_PART_ITEMS);

I’ve tried putting these lines before lv_meter_add_arc and also after it, however without results.

Code snippet

ui_meter_pressure = lv_meter_create(ui_Screen3);
lv_obj_center(ui_meter_pressure);
lv_obj_set_size(ui_meter_pressure, 240, 240);
lv_obj_set_style_bg_opa(ui_meter_pressure, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_opa(ui_meter_pressure, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_opa(ui_meter_pressure, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_outline_opa(ui_meter_pressure, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_outline_opa(ui_meter_pressure, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_pad_all(ui_meter_pressure, 0, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_text_font(ui_meter_pressure, &ui_font_Menu, LV_PART_TICKS | LV_STATE_DEFAULT);
lv_obj_set_style_text_color(ui_meter_pressure, lv_palette_main(LV_PALETTE_GREY), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_remove_style(ui_meter_pressure, NULL, LV_PART_INDICATOR);
/*Add a scale first*/
ui_scale_pressure = lv_meter_add_scale(ui_meter_pressure);
lv_meter_set_scale_ticks(ui_meter_pressure, ui_scale_pressure, 21, 2, SCR3_ARC_WIDTH, lv_color_hex(0x000000));
lv_meter_set_scale_major_ticks(ui_meter_pressure, ui_scale_pressure, 5, 4, SCR3_ARC_WIDTH, lv_color_hex(0xffffff), SCR3_ARC_WIDTH - 5);
lv_meter_set_scale_range(ui_meter_pressure, ui_scale_pressure, 0, 400, 270, 135);
/*Add a low pressure arc*/
ui_indic_pressure = lv_meter_add_arc(ui_meter_pressure, ui_scale_pressure, SCR3_ARC_WIDTH, lv_palette_main(LV_PALETTE_RED), 0);
lv_meter_set_indicator_start_value(ui_meter_pressure, ui_indic_pressure, 0);
lv_meter_set_indicator_end_value(ui_meter_pressure, ui_indic_pressure, DEFAULT_PRESSURE_LOW*100);

I did not find any ready made function that was able to change arc’s opacity, however I managed to do it through drawing events.

void ui_event_meter_cb(lv_event_t * e)
{
	lv_event_code_t code = lv_event_get_code(e);
	lv_obj_draw_part_dsc_t *dsc = (lv_obj_draw_part_dsc_t *)lv_event_get_param(e);
	
	if (code == LV_EVENT_DRAW_PART_BEGIN && dsc->type == LV_METER_DRAW_PART_ARC) {
		dsc->arc_dsc->opa = 180;
    }
}
1 Like