Set a scale line using non-integer values

All the examples seem to use uint32_t for the scale line value.

lv_scale_set_line_needle_value(lv_obj_t * obj, lv_obj_t * needle_line, int32_t needle_length, int32_t value);

This is ok in the case of the examples but I want to use it for a pressure gauge which shows 0 to 10 bar. Just showing each increment of 1 bar is too course. Is there a suggested way to have the line point at non-interger values on a scale?

You have to capture the draw event for the indicator and format the pressure your self. Like divide by 100 and use sprintf to format label_dsc->text

Thanks Paul - that makes sense.

At the moment I’ve got it working by calculating the line points myself as follows:

float angle = (pressure * 270) - 225;    // 270 degrees for full scale
float needle_length = 70;

pressure_needle_points[0].x = center;
pressure_needle_points[0].y = center;
pressure_needle_points[1].x = center + round(needle_length * cos(angle * M_PI / 180));
pressure_needle_points[1].y = center + round(needle_length * sin(angle * M_PI / 180));

lv_line_set_points(objects.scale_line_pressure, pressure_needle_points, 2);

I wonder though whether your method would be quicker/less overhead.

If I understand correctly, you have a scale with a range of 0 - 10 and you want to be able to set the needle at 1.5 for example. The scale labels 0 - 10 are drawn by the scale widget default behaviour.
In the previous version of lvgl (8.4) their are examples to customise the scale labels which is relative simple. In version 9 this has changed a lot, but it is still possible.
You can capture the draw event and check for INDICATOR part and LABEL draw taskj

Something like this, but I am still experimenting with it.

void meter::draw_event_cb_class(lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);
	lv_obj_t *obj = (lv_obj_t *)lv_event_get_target(e);

	lv_draw_task_t *draw_task = lv_event_get_draw_task(e);
	lv_draw_dsc_base_t *base_dsc = (lv_draw_dsc_base_t *)lv_draw_task_get_draw_dsc(draw_task);

	if (base_dsc->part == LV_PART_INDICATOR && lv_draw_task_get_type(draw_task) == LV_DRAW_TASK_TYPE_LABEL)
	{
		lv_obj_t *obj = lv_event_get_target_obj(e);
		lv_area_t coords;
		lv_obj_get_coords(obj, &coords);

		lv_draw_label_dsc_t *label_dsc = lv_draw_task_get_label_dsc(draw_task);
		//printf("%s",label_dsc->text);
	}
	
	/*if (code == LV_EVENT_DRAW_TASK_ADDED)
	{
		LV_PART_INDICATOR
		//lv_obj_send_event(parent_obj, LV_EVENT_DRAW_TASK_ADDED, lv_event_get_param(e));
	}*/
}