hal.c
// WARNING: This is not proper DPI.
// This is the bizarro concept of DPI for lvgl, which is more
// akin to setting *some* scaling, mostly default sizes and paddings.
// Font has to be handled separately from their "DPI".
// Here we're using this to scale the UI better according to the resolution,
// and not according to the device size.
This is not proper DPI.
This is the bizarro concept of DPI for lvgl, which is more
akin to setting *some* scaling, mostly default sizes and paddings.
Font has to be handled separately from their "DPI".
Here we're using this to scale the UI better according to the resolution,
and not according to the device size.
This is not proper DPI . This is the bizarro concept of DPI for lvgl which is more akin to setting * some * scaling mostly default sizes and paddings . Font has to be handled separately from their " DPI " . Here we ' re using this to scale the UI better according to the resolution and not according to the device size .
void hal_set_dpi()
{
	int ret = 0;
	if (disp_drv.hor_res < disp_drv.ver_res) {
		mn_hal_default_dpi = 200*(disp_drv.hor_res)/720;
	}
	else {
		mn_hal_default_dpi = 200*(disp_drv.ver_res)/720;
	}
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
	printf("[LVGUI:HAL] Computed 'DPI': %d\n", mn_hal_default_dpi);
#endif
	lv_freetype_init(255);
	static lv_font_t font;
	ret = lv_freetype_font_init(&font, hal_asset_path("fonts/Roboto-Regular.ttf"), POINTS_SCALE(24));
	if (ret == FT_Err_Ok) {
		mn_hal_default_font = (void *)&font;
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
		printf("[LVGUI:HAL] Default font size: %d\n", POINTS_SCALE(24));
#endif
	}
	else {
		LV_LOG_ERROR("Could not load font; falling back to built-in Roboto@22...");
		mn_hal_default_font = &lv_font_roboto_22;
	}
}
void hal_set_dpi ( ) { int ret = 0 ; if ( disp_drv . hor_res < disp_drv . ver_res ) { mn_hal_default_dpi = 200 * ( disp_drv . hor_res ) / 720 ; } else { mn_hal_default_dpi = 200 * ( disp_drv . ver_res ) / 720 ; } #if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO printf ( " \n " , mn_hal_default_dpi ) ; #endif lv_freetype_init ( 255 ) ; static lv_font_t font ; ret = lv_freetype_font_init ( & font , hal_asset_path ( " " ) , POINTS_SCALE ( 24 ) ) ; if ( ret == FT_Err_Ok ) { mn_hal_default_font = ( void * ) & font ; #if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO printf ( " \n " , POINTS_SCALE ( 24 ) ) ; #endif } else { LV_LOG_ERROR ( " " ) ; mn_hal_default_font = & lv_font_roboto_22 ; } }
WARNING: This is not proper DPI.
WARNING : This is not proper DPI .
// This needs to happen before lv_init. // This means we need to figure out the DPI before hal_init :( // Portrait mode // Landscape mode // Not strictly DPI, but fonts don't actually scale with DPI // so we need to handle it ourselves. // Init freetype with this many cached glyphs // Font we're going to use