I had problems to visualize labels on major ticks in meter (gauge).
Using Windows Simulator, Visual Studio and lvgl v9.0
After a fre says I have found a solution.
#include “…/…/lv_examples.h”
int rumbo = 270;
//--------------------//
// COMPASS CON MOSCA //
//--------------------//
void lv_compass(void){
//------------------------------------------------------------
// Objetos - Creación - en algunos casos se les da atributos
//------------------------------------------------------------
// Objeto principal en pantalla actual definida en main()
lv_obj_t* obj1 = lv_obj_create(lv_scr_act());
lv_obj_set_width(obj1, 400);
lv_obj_set_height(obj1, 400);
lv_obj_set_x(obj1, 0);
lv_obj_set_y(obj1, 0);
//------------------------------------------------------------
lv_obj_t* gauge_bg = lv_img_create(obj1, NULL);
// Textos fijos
lv_obj_t* rpmLabel = lv_label_create(obj1, NULL);
// Medidor y su indicador
lv_obj_t* rumbo1 = lv_meter_create(gauge_bg, NULL);
lv_meter_indicator_t* needle1;
lv_obj_center(rumbo1);
lv_obj_remove_style_all(rumbo1);
lv_obj_center(rumbo1);
lv_obj_set_size(rumbo1, 350, 350);
//---------------------------------------------
// Estilos de Objetos, textos , etc
//---------------------------------------------
static lv_style_t style1;
lv_style_init(&style1);
lv_style_set_bg_color(&style1, lv_color_black());
lv_obj_add_style(obj1, &style1, LV_PART_MAIN );
lv_style_set_border_width(&style1, LV_STATE_DEFAULT, 4);
lv_style_set_radius(&style1, LV_STATE_DEFAULT, 6);
//-----------------------------------------------------------
// Estilo de texto para indicar las RPM en numérico grande
static lv_style_t boostStyle;
lv_style_init(&boostStyle);
lv_style_set_text_color(&boostStyle, lv_color_white());
lv_style_set_text_font(&boostStyle, &lv_font_montserrat_38);
//------------------------------------------------------------
// Estilo texto para textos pequeños
static lv_style_t textoStyle;
lv_style_init(&textoStyle);
lv_style_set_text_color(&textoStyle, lv_color_white());
lv_style_set_text_font(&textoStyle, &lv_font_montserrat_14);
//------------------------------------------------------------
// Atributos de objetos más detallados
//------------------------------------------------
// Definir escalas del medidor
lv_meter_set_scale_ticks(rumbo1, 73, 4, 18, lv_color_white());
lv_meter_set_scale_major_ticks(rumbo1, 6, 4, 26, lv_color_white(), 25);
lv_meter_set_scale_range(rumbo1, 0, 36, 360, -90);
lv_obj_set_style_text_color(rumbo1, lv_color_white(), LV_PART_TICKS );
// Tamaño texto de la escala
lv_obj_set_style_text_font(rumbo1, &lv_font_montserrat_28, LV_PART_MAIN);
}
I have solved adding code to lv_meter:
In line 471
lv_area_t label_cord;
label_cord.x1 = p.x - label_size.x / 2;
label_cord.y1 = p.y - label_size.y / 2;
label_cord.x2 = label_cord.x1 + label_size.x;
label_cord.y2 = label_cord.y1 + label_size.y;
label_dsc.text = buf; // Added by me
lv_draw_label(layer, &label_dsc, &label_cord);