1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

theme updates

This commit is contained in:
Gabor Kiss-Vamosi 2020-04-14 09:55:11 +02:00
parent 634df1da8a
commit e5254bdfef
12 changed files with 169 additions and 19 deletions

View File

@ -145,6 +145,15 @@ static inline void lv_scr_load(lv_obj_t * scr)
#define LV_VER_RES lv_disp_get_ver_res(lv_disp_get_default())
#endif
/**
* Same as Android's DIP. (Different name is chosen to avoid mistype between LV_DPI and LV_DIP)
* 1 dip is 1 px on a 160 DPI screen
* 1 dip is 2 px on a 320 DPI screen
* https://stackoverflow.com/questions/2025282/what-is-the-difference-between-px-dip-dp-and-sp
*/
#define LV_DPX(n) LV_MATH_MAX(((LV_DPI * (n)) / 160), 1)
#ifdef __cplusplus
} /* extern "C" */
#endif

View File

@ -733,14 +733,6 @@ static inline lv_res_t lv_style_list_get_data_ptr(lv_style_list_t * list, lv_sty
*/
#define LV_STYLE_CREATE(name, copy_p) static lv_style_t name; lv_style_init(&name); lv_style_copy(&name, copy);
/**
* Same as Android's DIP. (Different name is chosen to avoid mistype between LV_DPI and LV_DIP)
* 1 dip is 1 px on a 160 DPI screen
* 1 dip is 2 px on a 320 DPI screen
* https://stackoverflow.com/questions/2025282/what-is-the-difference-between-px-dip-dp-and-sp
*/
#define LV_DPX(n) LV_MATH_MAX(((LV_DPI * (n)) / 160), 1)
#ifdef __cplusplus
} /* extern "C" */

View File

@ -92,11 +92,11 @@ void lv_draw_rect(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect
draw_shadow(coords, clip, dsc);
#endif
draw_outline(coords, clip, dsc);
draw_bg(coords, clip, dsc);
draw_pattern(coords, clip, dsc);
draw_border(coords, clip, dsc);
draw_value(coords, clip, dsc);
draw_outline(coords, clip, dsc);
LV_ASSERT_MEM_INTEGRITY();
}

View File

@ -64,6 +64,7 @@ void lv_disp_drv_init(lv_disp_drv_t * driver)
driver->buffer = NULL;
driver->rotated = 0;
driver->color_chroma_key = LV_COLOR_TRANSP;
driver->dpi = LV_DPI;
#if LV_ANTIALIAS
driver->antialiasing = true;
@ -265,6 +266,36 @@ bool lv_disp_get_antialiasing(lv_disp_t * disp)
#endif
}
/**
* Get the DPI of the display
* @param disp pointer to a display (NULL to use the default display)
* @return dpi of the display
*/
uint32_t lv_disp_get_dpi(lv_disp_t * disp)
{
if(disp == NULL) disp = lv_disp_get_default();
if(disp == NULL) return 1; /*Do not return 0 because it might be a divider*/
return disp->driver.dpi;
}
/**
* Get the size category of the display based on it's hor. res. and dpi.
* @param disp pointer to a display (NULL to use the default display)
* @return LV_DISP_SIZE_SMALL/MEDIUM/LARGE/EXTRA_LARGE
*/
lv_disp_size_t lv_disp_get_size_category(lv_disp_t * disp)
{
if(disp == NULL) disp = lv_disp_get_default();
if(disp == NULL) return LV_DISP_SIZE_SMALL;
uint32_t w = lv_disp_get_hor_res(disp) * 10 / disp->driver.dpi;
if(w < LV_DISP_SMALL_LIMIT) return LV_DISP_SIZE_SMALL;
if(w < LV_DISP_MEDIUM_LIMIT) return LV_DISP_SIZE_MEDIUM;
if(w < LV_DISP_LARGE_LIMIT) return LV_DISP_SIZE_LARGE;
else return LV_DISP_SIZE_EXTRA_LARGE;
}
/**
* Call in the display driver's `flush_cb` function when the flushing is finished
* @param disp_drv pointer to display driver in `flush_cb` where this function is called

View File

@ -81,6 +81,11 @@ typedef struct _disp_drv_t {
uint32_t screen_transp : 1;
#endif
/** DPI (dot per inch) of the display.
* Set to `LV_DPI` from `lv_Conf.h` by default.
*/
uint32_t dpi :10;
/** MANDATORY: Write the internal buffer (VDB) to the display. 'lv_disp_flush_ready()' has to be
* called when finished */
void (*flush_cb)(struct _disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
@ -147,6 +152,14 @@ typedef struct _disp_t {
uint32_t last_activity_time; /**< Last time there was activity on this display */
} lv_disp_t;
typedef enum {
LV_DISP_SIZE_SMALL,
LV_DISP_SIZE_MEDIUM,
LV_DISP_SIZE_LARGE,
LV_DISP_SIZE_EXTRA_LARGE,
}lv_disp_size_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@ -230,6 +243,13 @@ lv_coord_t lv_disp_get_ver_res(lv_disp_t * disp);
*/
bool lv_disp_get_antialiasing(lv_disp_t * disp);
/**
* Get the size category of the display based on it's hor. res. and dpi.
* @param disp pointer to a display (NULL to use the default display)
* @return LV_DISP_SIZE_SMALL/MEDIUM/LARGE/EXTRA_LARGE
*/
lv_disp_size_t lv_disp_get_size_category(lv_disp_t * disp);
/**
* Call in the display driver's `flush_cb` function when the flushing is finished
* @param disp_drv pointer to display driver in `flush_cb` where this function is called

View File

@ -53,6 +53,59 @@ lv_theme_t * lv_theme_get_act(void)
return act_theme;
}
/**
* Get the small font of the theme
* @return pointer to the font
*/
const lv_font_t * lv_theme_get_font_small(void)
{
return act_theme->font_small;
}
/**
* Get the normal font of the theme
* @return pointer to the font
*/
const lv_font_t * lv_theme_get_font_normal(void)
{
return act_theme->font_normal;
}
/**
* Get the subtitle font of the theme
* @return pointer to the font
*/
const lv_font_t * lv_theme_get_font_subtitle(void)
{
return act_theme->font_subtitle;
}
/**
* Get the title font of the theme
* @return pointer to the font
*/
const lv_font_t * lv_theme_get_font_title(void)
{
return act_theme->font_title;
}
/**
* Get the primary color of the theme
* @return the color
*/
lv_color_t lv_theme_get_color_primary(void)
{
return act_theme->color_primary;
}
/**
* Get the flags of the theme
* @return the flags
*/
uint32_t lv_theme_get_flags(void)
{
return act_theme->flags;
}
void lv_theme_apply(lv_obj_t * obj, lv_theme_style_t name)
{

View File

@ -175,7 +175,43 @@ lv_style_t * lv_theme_get_style(lv_theme_style_t name);
void lv_theme_apply(lv_obj_t * obj, lv_theme_style_t name);
lv_style_t * lv_theme_get_style_part(lv_theme_style_t name, uint8_t part);
/**
* Get the small font of the theme
* @return pointer to the font
*/
const lv_font_t * lv_theme_get_font_small(void);
/**
* Get the normal font of the theme
* @return pointer to the font
*/
const lv_font_t * lv_theme_get_font_normal(void);
/**
* Get the subtitle font of the theme
* @return pointer to the font
*/
const lv_font_t * lv_theme_get_font_subtitle(void);
/**
* Get the title font of the theme
* @return pointer to the font
*/
const lv_font_t * lv_theme_get_font_title(void);
/**
* Get the primary color of the theme
* @return the color
*/
lv_color_t lv_theme_get_color_primary(void);
/**
* Get the flags of the theme
* @return the flags
*/
uint32_t lv_theme_get_flags(void);
/**********************
* MACROS

View File

@ -191,7 +191,8 @@ static void basic_init(void)
lv_style_set_bg_color(&scr, LV_STATE_DEFAULT, COLOR_SCR);
lv_style_set_text_color(&scr, LV_STATE_DEFAULT, COLOR_SCR_TEXT);
lv_style_set_value_color(&scr, LV_STATE_DEFAULT, COLOR_SCR_TEXT);
lv_style_set_border_post(&scr, LV_STATE_DEFAULT, true);
lv_style_set_text_font(&scr, LV_STATE_DEFAULT, theme.font_normal);
lv_style_set_value_font(&scr, LV_STATE_DEFAULT, theme.font_normal);
style_init_reset(&bg);
lv_style_set_radius(&bg, LV_STATE_DEFAULT, LV_DPX(8));
@ -203,6 +204,7 @@ static void basic_init(void)
lv_style_set_border_post(&bg, LV_STATE_DEFAULT, true);
lv_style_set_text_font(&bg, LV_STATE_DEFAULT, theme.font_normal);
lv_style_set_text_color(&bg, LV_STATE_DEFAULT, COLOR_BG_TEXT);
lv_style_set_value_font(&bg, LV_STATE_DEFAULT, theme.font_normal);
lv_style_set_value_color(&bg, LV_STATE_DEFAULT, COLOR_BG_TEXT);
lv_style_set_image_recolor(&bg, LV_STATE_DEFAULT, COLOR_BG_TEXT);
lv_style_set_line_color(&bg, LV_STATE_DEFAULT, COLOR_BG_TEXT);
@ -409,10 +411,10 @@ static void switch_init(void)
lv_style_set_bg_opa(&sw_knob, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&sw_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_style_set_radius(&sw_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_style_set_pad_top(&sw_knob, LV_STATE_DEFAULT, - LV_DPX(10));
lv_style_set_pad_bottom(&sw_knob, LV_STATE_DEFAULT, - LV_DPX(10));
lv_style_set_pad_left(&sw_knob, LV_STATE_DEFAULT, - LV_DPX(10));
lv_style_set_pad_right(&sw_knob, LV_STATE_DEFAULT, - LV_DPX(10));
lv_style_set_pad_top(&sw_knob, LV_STATE_DEFAULT, - LV_DPX(8));
lv_style_set_pad_bottom(&sw_knob, LV_STATE_DEFAULT, - LV_DPX(8));
lv_style_set_pad_left(&sw_knob, LV_STATE_DEFAULT, - LV_DPX(8));
lv_style_set_pad_right(&sw_knob, LV_STATE_DEFAULT, - LV_DPX(8));
#endif
}
@ -633,7 +635,7 @@ static void page_init(void)
#if LV_USE_PAGE
style_init_reset(&sb);
lv_style_set_bg_opa(&sb, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&sb, LV_STATE_DEFAULT, (IS_LIGHT ? lv_color_hex(0xcccfd1) : lv_color_hex(0x505559)));
lv_style_set_bg_color(&sb, LV_STATE_DEFAULT, (IS_LIGHT ? lv_color_hex(0xcccfd1) : lv_color_hex(0x777f85)));
lv_style_set_radius(&sb, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_style_set_size(&sb, LV_STATE_DEFAULT, LV_DPX(7));
lv_style_set_pad_right(&sb, LV_STATE_DEFAULT, LV_DPX(7));

View File

@ -214,6 +214,8 @@ static lv_design_res_t lv_led_design(lv_obj_t * led, const lv_area_t * clip_area
* and LV_LED_BRIGHT_ON*/
rect_dsc.shadow_width = ((ext->bright - LV_LED_BRIGHT_MIN) * rect_dsc.shadow_width) /
(LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN);
rect_dsc.shadow_spread = ((ext->bright - LV_LED_BRIGHT_MIN) * rect_dsc.shadow_spread) /
(LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN);
lv_draw_rect(&led->coords, clip_area, &rect_dsc);
}

View File

@ -102,7 +102,12 @@ lv_obj_t * lv_msgbox_create(lv_obj_t * par, const lv_obj_t * copy)
lv_cont_set_layout(mbox, LV_LAYOUT_COLUMN_MID);
lv_cont_set_fit2(mbox, LV_FIT_NONE, LV_FIT_TIGHT);
lv_obj_set_width(mbox, LV_DPI * 2);
lv_coord_t fit_w = lv_obj_get_width_fit(par);
if(lv_disp_get_size_category(NULL) <= LV_DISP_SIZE_SMALL) {
lv_obj_set_width(mbox, fit_w);
} else {
lv_obj_set_width(mbox, LV_MATH_MIN(fit_w, LV_DPX(400)));
}
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_event_cb(mbox, lv_msgbox_default_event_cb);

View File

@ -115,7 +115,7 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy)
lv_theme_apply(roller, LV_THEME_ROLLER);
refr_height(roller);
lv_roller_set_visible_row_count(roller, 4);
lv_roller_set_visible_row_count(roller, 3);
}
/*Copy an existing roller*/
else {

View File

@ -89,7 +89,7 @@ lv_obj_t * lv_switch_create(lv_obj_t * par, const lv_obj_t * copy)
if(copy == NULL) {
lv_obj_set_click(sw, true);
lv_obj_add_protect(sw, LV_PROTECT_PRESS_LOST);
lv_obj_set_size(sw, 4 * LV_DPI / 10, LV_DPI / 4);
lv_obj_set_size(sw, LV_DPX(70), LV_DPX(40));
lv_bar_set_range(sw, 0, 1);
lv_theme_apply(sw, LV_THEME_SWITCH);