I draw the base and round it off to serve as a background.
The code for this is:
void gauge_background(void)
{
lv_obj_clear_flag(background, LV_OBJ_FLAG_SCROLLABLE); /// Flags
lv_obj_set_size(background, 360, 360);
lv_obj_set_style_radius(background, LV_RADIUS_CIRCLE, 0); // display becomes ROUND
lv_obj_set_style_bg_color(background, lv_color_hex(0x8B4513), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_bg_opa(background, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_center(background);
}
I draw a round scale.
The code for this is:
Don’t be confused by the name of the function horizontal_line, it is intended for a linear scale
void horizontal_line(void)
{
lv_obj_t * scale_horizon_line = lv_scale_create(lv_screen_active());
// lv_scale_set_mode(scale_horizon_line, LV_SCALE_MODE_HORIZONTAL_TOP);
lv_scale_set_mode(scale_horizon_line, LV_SCALE_MODE_ROUND_OUTER);
lv_obj_set_size(scale_horizon_line, 360, 360);
lv_obj_center(scale_horizon_line);
lv_obj_set_pos(scale_horizon_line, 0, 0); // X->, Y-⌄
}
Turn the scale on on +200 degrees.
Moreover, the rotation is from the conditional starting point or coordinate, which is laid down in the main file:
To rotate the circular scale, you need to add one line to the code:
void horizontal_line(void)
{
lv_obj_t * scale_horizon_line = lv_scale_create(lv_screen_active());
// lv_scale_set_mode(scale_horizon_line, LV_SCALE_MODE_HORIZONTAL_TOP);
lv_scale_set_mode(scale_horizon_line, LV_SCALE_MODE_ROUND_OUTER);
lv_obj_set_size(scale_horizon_line, 360, 360);
lv_obj_center(scale_horizon_line);
lv_obj_set_pos(scale_horizon_line, 0, 0); // X->, Y-⌄
lv_scale_set_rotation(scale_horizon_line, 200);
}
Now I’m trying to draw a linear scale.
The code for this is:
void horizontal_line(void)
{
lv_obj_t * scale_horizon_line = lv_scale_create(lv_screen_active());
lv_scale_set_mode(scale_horizon_line, LV_SCALE_MODE_HORIZONTAL_TOP);
// lv_scale_set_mode(scale_horizon_line, LV_SCALE_MODE_ROUND_OUTER);
lv_obj_set_size(scale_horizon_line, 360, 360);
lv_obj_center(scale_horizon_line);
lv_obj_set_pos(scale_horizon_line, 0, 0); // X->, Y-⌄
}
I try to rotate the linear scale on 80 degrees… and as you can see, nothing happens.
The code for this is:
void horizontal_line(void)
{
lv_obj_t * scale_horizon_line = lv_scale_create(lv_screen_active());
lv_scale_set_mode(scale_horizon_line, LV_SCALE_MODE_HORIZONTAL_TOP);
// lv_scale_set_mode(scale_horizon_line, LV_SCALE_MODE_ROUND_OUTER);
lv_obj_set_size(scale_horizon_line, 360, 360);
lv_obj_center(scale_horizon_line);
lv_obj_set_pos(scale_horizon_line, 0, 0); // X->, Y-⌄
lv_scale_set_rotation(scale_horizon_line, 80);
}
And another oddity, you specify the flag
LV_SCALE_MODE_HORIZONTAL_TOP
and the scale is drawn at the bottom, you specify the flag
LV_SCALE_MODE_HORIZONTAL_BOTTOM
and the scale is drawn at the top
Similarly, rotation does not work for flags
LV_SCALE_MODE_VERTICAL_LEFT
LV_SCALE_MODE_VERTICAL_RIGHT
I also tried rotate a simple line, but that doesn’t work either, and created the line in two ways.
With just code:
/*Create a line and apply the new style*/
lv_obj_t * horizon_line;
horizon_line = lv_line_create(lv_screen_active());
lv_obj_set_style_length(horizon_line, 100, 0);
lv_obj_set_style_line_width(horizon_line, 6, LV_PART_INDICATOR); // Setting the thickness
lv_obj_set_style_line_color(horizon_line, lv_color_hex(0xFFFFFF), 0); // Set the line color to white
lv_obj_center(horizon_line);
lv_obj_set_style_transform_rotation(horizon_line, 1800, LV_PART_MAIN | LV_STATE_DEFAULT);
In this case, the line is not drawn at all
With added style:
/*Create a line and apply the new style*/
lv_obj_t * horizon_line;
horizon_line = lv_line_create(lv_screen_active());
static lv_point_precise_t line_points[] = { {0, 0}, {360, 0}};
// /*Create style*/
static lv_style_t style_line;
lv_style_init(&style_line);
lv_style_set_line_width(&style_line, 4); // Setting the thickness
// lv_style_set_line_color(&style_line, lv_palette_main(LV_PALETTE_YELLOW));
lv_style_set_line_color(&style_line, lv_color_hex(0xFFFFFF)); // Set the line color to white
lv_line_set_points(horizon_line, line_points, 2); /*Set the points*/
lv_obj_add_style(horizon_line, &style_line, 0);
lv_obj_center(horizon_line);
lv_style_set_transform_rotation(&style_line, 20);
The line is drawn, but there is no rotation.
On the this forum and on github there were questions about where the meter from lvgl 8.3
disappeared to, it was much more convenient and productive and solved some problems.
Now the use of one widget has replaced everything, but behind the universality hides the impossibility of creating simple things