1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

add lv_font_monospace_8 (uniscii) as built-in font

This commit is contained in:
Gabor Kiss-Vamosi 2018-07-25 22:57:36 +02:00
parent 7cc8e74d1a
commit a1abe14414
7 changed files with 4659 additions and 27 deletions

View File

@ -142,6 +142,8 @@
#define USE_LV_FONT_DEJAVU_40_CYRILLIC 0 #define USE_LV_FONT_DEJAVU_40_CYRILLIC 0
#define USE_LV_FONT_SYMBOL_40 0 #define USE_LV_FONT_SYMBOL_40 0
#define USE_LV_FONT_MONOSPACE_8 0
/* Optionally declare your custom fonts here. /* Optionally declare your custom fonts here.
* You can use these fonts as defult font too * You can use these fonts as defult font too
* and they will be avialale globally. E.g. * and they will be avialale globally. E.g.

View File

@ -74,23 +74,21 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_st
pos.x = coords->x1; pos.x = coords->x1;
pos.y = coords->y1; pos.y = coords->y1;
/*Align the line to middle if enabled*/ /*Align to middle*/
if(flag & LV_TXT_FLAG_CENTER) { if(flag & LV_TXT_FLAG_CENTER) {
line_width = lv_txt_get_width(&txt[line_start], line_end - line_start, line_width = lv_txt_get_width(&txt[line_start], line_end - line_start,
font, style->text.letter_space, flag); font, style->text.letter_space, flag);
/*Trim closing spaces.*/
uint16_t i; pos.x += (w - line_width) / 2;
for(i = line_end - 1; i > 0; i--) {
if(txt[i] == ' ' || txt[i] == '\n' || txt[i] == '\r') {
line_width -= lv_font_get_width(font, txt[i]);
line_width -= style->text.letter_space;
} else {
break;
}
}
pos.x += (w - line_width) / 2;
} }
/*Align to the right*/
else if(flag & LV_TXT_FLAG_RIGHT) {
line_width = lv_txt_get_width(&txt[line_start], line_end - line_start,
font, style->text.letter_space, flag);
pos.x = w - line_width;
}
lv_opa_t opa = (uint16_t)((uint16_t) style->text.opa * opa_scale) >> 8; lv_opa_t opa = (uint16_t)((uint16_t) style->text.opa * opa_scale) >> 8;
@ -180,19 +178,16 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_st
line_width = lv_txt_get_width(&txt[line_start], line_end - line_start, line_width = lv_txt_get_width(&txt[line_start], line_end - line_start,
font, style->text.letter_space, flag); font, style->text.letter_space, flag);
/*Trim closing spaces.*/ pos.x += (w - line_width) / 2;
uint16_t i;
for(i = line_end - 1; i > line_start; i--) {
if(txt[i] == ' ' || txt[i] == '\n' || txt[i] == '\r') {
line_width -= lv_font_get_width(font, txt[i]);
line_width -= style->text.letter_space;
} else {
break;
}
}
pos.x += (w - line_width) / 2;
} }
/*Align to the right*/
else if(flag & LV_TXT_FLAG_RIGHT) {
line_width = lv_txt_get_width(&txt[line_start], line_end - line_start,
font, style->text.letter_space, flag);
pos.x = w - line_width;
}
/*Go the next line position*/ /*Go the next line position*/
pos.y += lv_font_get_height(font); pos.y += lv_font_get_height(font);
pos.y += style->text.line_space; pos.y += style->text.line_space;

View File

@ -114,6 +114,10 @@ LV_FONT_DECLARE(lv_font_dejavu_40_cyrillic);
LV_FONT_DECLARE(lv_font_symbol_40); LV_FONT_DECLARE(lv_font_symbol_40);
#endif #endif
#if USE_LV_FONT_MONOSPACE_8
LV_FONT_DECLARE(lv_font_monospace_8);
#endif
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -38,6 +38,7 @@ typedef enum
LV_TXT_FLAG_RECOLOR = 0x01, /*Enable parsing of recolor command*/ LV_TXT_FLAG_RECOLOR = 0x01, /*Enable parsing of recolor command*/
LV_TXT_FLAG_EXPAND = 0x02, /*Ignore width (Used by the library)*/ LV_TXT_FLAG_EXPAND = 0x02, /*Ignore width (Used by the library)*/
LV_TXT_FLAG_CENTER = 0x04, /*Align the text to the middle*/ LV_TXT_FLAG_CENTER = 0x04, /*Align the text to the middle*/
LV_TXT_FLAG_RIGHT = 0x08, /*Align the text to the right*/
} lv_txt_flag_t; } lv_txt_flag_t;
typedef enum typedef enum

View File

@ -467,11 +467,17 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, lv_point_t * pos)
line_w = lv_txt_get_width(&txt[line_start], new_line_start - line_start, line_w = lv_txt_get_width(&txt[line_start], new_line_start - line_start,
font, style->text.letter_space, flag); font, style->text.letter_space, flag);
x += lv_obj_get_width(label) / 2 - line_w / 2; x += lv_obj_get_width(label) / 2 - line_w / 2;
}
else if(ext->align == LV_LABEL_ALIGN_RIGHT) {
lv_coord_t line_w;
line_w = lv_txt_get_width(&txt[line_start], new_line_start - line_start,
font, style->text.letter_space, flag);
x += lv_obj_get_width(label) - line_w;
} }
pos->x = x; pos->x = x;
pos->y = y; pos->y = y;
} }
/** /**
@ -657,12 +663,13 @@ static bool lv_label_design(lv_obj_t * label, const lv_area_t * mask, lv_design_
} }
/*TEST: draw a background for the label*/ /*TEST: draw a background for the label*/
// lv_draw_rect(&label->coords, mask, &lv_style_plain_color); //lv_draw_rect(&label->coords, mask, &lv_style_plain_color, LV_OPA_COVER);
lv_txt_flag_t flag = LV_TXT_FLAG_NONE; lv_txt_flag_t flag = LV_TXT_FLAG_NONE;
if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR; if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND; if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
if(ext->align == LV_LABEL_ALIGN_CENTER) flag |= LV_TXT_FLAG_CENTER; if(ext->align == LV_LABEL_ALIGN_CENTER) flag |= LV_TXT_FLAG_CENTER;
if(ext->align == LV_LABEL_ALIGN_RIGHT) flag |= LV_TXT_FLAG_RIGHT;
lv_draw_label(&coords, mask, style, opa_scale, ext->text, flag, &ext->offset); lv_draw_label(&coords, mask, style, opa_scale, ext->text, flag, &ext->offset);
} }

View File

@ -50,6 +50,7 @@ typedef enum
typedef enum { typedef enum {
LV_LABEL_ALIGN_LEFT, LV_LABEL_ALIGN_LEFT,
LV_LABEL_ALIGN_CENTER, LV_LABEL_ALIGN_CENTER,
LV_LABEL_ALIGN_RIGHT,
} lv_label_align_t; } lv_label_align_t;
/*Data of label*/ /*Data of label*/