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:
parent
7cc8e74d1a
commit
a1abe14414
@ -142,6 +142,8 @@
|
||||
#define USE_LV_FONT_DEJAVU_40_CYRILLIC 0
|
||||
#define USE_LV_FONT_SYMBOL_40 0
|
||||
|
||||
#define USE_LV_FONT_MONOSPACE_8 0
|
||||
|
||||
/* Optionally declare your custom fonts here.
|
||||
* You can use these fonts as defult font too
|
||||
* and they will be avialale globally. E.g.
|
||||
|
@ -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.y = coords->y1;
|
||||
|
||||
/*Align the line to middle if enabled*/
|
||||
/*Align to middle*/
|
||||
if(flag & LV_TXT_FLAG_CENTER) {
|
||||
line_width = lv_txt_get_width(&txt[line_start], line_end - line_start,
|
||||
font, style->text.letter_space, flag);
|
||||
/*Trim closing spaces.*/
|
||||
uint16_t i;
|
||||
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;
|
||||
}
|
||||
}
|
||||
line_width = lv_txt_get_width(&txt[line_start], line_end - line_start,
|
||||
font, style->text.letter_space, flag);
|
||||
|
||||
pos.x += (w - line_width) / 2;
|
||||
|
||||
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;
|
||||
|
||||
@ -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,
|
||||
font, style->text.letter_space, flag);
|
||||
|
||||
/*Trim closing spaces.*/
|
||||
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;
|
||||
|
||||
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*/
|
||||
pos.y += lv_font_get_height(font);
|
||||
pos.y += style->text.line_space;
|
||||
|
@ -114,6 +114,10 @@ LV_FONT_DECLARE(lv_font_dejavu_40_cyrillic);
|
||||
LV_FONT_DECLARE(lv_font_symbol_40);
|
||||
#endif
|
||||
|
||||
#if USE_LV_FONT_MONOSPACE_8
|
||||
LV_FONT_DECLARE(lv_font_monospace_8);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
4622
lv_fonts/lv_font_monospace_8.c
Normal file
4622
lv_fonts/lv_font_monospace_8.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -38,6 +38,7 @@ typedef enum
|
||||
LV_TXT_FLAG_RECOLOR = 0x01, /*Enable parsing of recolor command*/
|
||||
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_RIGHT = 0x08, /*Align the text to the right*/
|
||||
} lv_txt_flag_t;
|
||||
|
||||
typedef enum
|
||||
|
@ -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,
|
||||
font, style->text.letter_space, flag);
|
||||
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->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*/
|
||||
// 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;
|
||||
if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
|
||||
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_RIGHT) flag |= LV_TXT_FLAG_RIGHT;
|
||||
|
||||
lv_draw_label(&coords, mask, style, opa_scale, ext->text, flag, &ext->offset);
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ typedef enum
|
||||
typedef enum {
|
||||
LV_LABEL_ALIGN_LEFT,
|
||||
LV_LABEL_ALIGN_CENTER,
|
||||
LV_LABEL_ALIGN_RIGHT,
|
||||
} lv_label_align_t;
|
||||
|
||||
/*Data of label*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user