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

txt position fixes

This commit is contained in:
Gabor Kiss-Vamosi 2019-01-07 07:06:31 +01:00
parent ced3903100
commit d3fab62f8f
7 changed files with 27 additions and 15 deletions

View File

@ -95,7 +95,7 @@ void lv_style_init(void)
lv_style_scr.text.color = LV_COLOR_MAKE(0x30, 0x30, 0x30); lv_style_scr.text.color = LV_COLOR_MAKE(0x30, 0x30, 0x30);
lv_style_scr.text.font = LV_FONT_DEFAULT; lv_style_scr.text.font = LV_FONT_DEFAULT;
lv_style_scr.text.letter_space = 2; lv_style_scr.text.letter_space = 2;
lv_style_scr.text.line_space = 2; lv_style_scr.text.line_space = 1;
lv_style_scr.image.opa = LV_OPA_COVER; lv_style_scr.image.opa = LV_OPA_COVER;
lv_style_scr.image.color = LV_COLOR_MAKE(0x20, 0x20, 0x20); lv_style_scr.image.color = LV_COLOR_MAKE(0x20, 0x20, 0x20);

View File

@ -212,7 +212,7 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
/** /**
* Give the length of a text with a given font * Give the length of a text with a given font
* @param txt a '\0' terminate string * @param txt a '\0' terminate string
* @param length length of 'txt' in character count and not bytes(UTF-8 can be 1,2,3 or 4 bytes long) * @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in UTF-8)
* @param font pointer to a font * @param font pointer to a font
* @param letter_space letter space * @param letter_space letter space
* @param flags settings for the text from 'txt_flag_t' enum * @param flags settings for the text from 'txt_flag_t' enum
@ -224,13 +224,13 @@ lv_coord_t lv_txt_get_width(const char * txt, uint16_t length,
if(txt == NULL) return 0; if(txt == NULL) return 0;
if(font == NULL) return 0; if(font == NULL) return 0;
uint32_t i = 0, j; uint32_t i = 0;
lv_coord_t width = 0; lv_coord_t width = 0;
lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT; lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;
uint32_t letter; uint32_t letter;
if(length != 0) { if(length != 0) {
for(j=0; j< length; j++){ while(i< length){
letter = lv_txt_encoded_next(txt, &i); letter = lv_txt_encoded_next(txt, &i);
if((flag & LV_TXT_FLAG_RECOLOR) != 0) { if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
if(lv_txt_is_cmd(&cmd_state, letter) != false) { if(lv_txt_is_cmd(&cmd_state, letter) != false) {

View File

@ -82,7 +82,7 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
/** /**
* Give the length of a text with a given font * Give the length of a text with a given font
* @param txt a '\0' terminate string * @param txt a '\0' terminate string
* @param length length of 'txt' in character count and not bytes(UTF-8 can be 1,2,3 or 4 bytes long) * @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in UTF-8)
* @param font pointer to a font * @param font pointer to a font
* @param letter_space letter space * @param letter_space letter space
* @param flags settings for the text from 'txt_flag_t' enum * @param flags settings for the text from 'txt_flag_t' enum

View File

@ -14,6 +14,7 @@
#include "../lv_misc/lv_math.h" #include "../lv_misc/lv_math.h"
#include "../lv_core/lv_indev.h" #include "../lv_core/lv_indev.h"
#include "../lv_themes/lv_theme.h" #include "../lv_themes/lv_theme.h"
#include <strings.h>
/********************* /*********************
* DEFINES * DEFINES
@ -756,7 +757,7 @@ static void draw_header(lv_obj_t * calendar, const lv_area_t * mask)
/*Add the right arrow*/ /*Add the right arrow*/
arrow_style = ext->btn_pressing > 0 ? ext->style_header_pr : ext->style_header; arrow_style = ext->btn_pressing > 0 ? ext->style_header_pr : ext->style_header;
header_area.x1 = header_area.x2 - ext->style_header->body.padding.hor - header_area.x1 = header_area.x2 - ext->style_header->body.padding.hor -
lv_txt_get_width(SYMBOL_RIGHT, 1, arrow_style->text.font, lv_txt_get_width(SYMBOL_RIGHT, strlen(SYMBOL_RIGHT), arrow_style->text.font,
arrow_style->text.line_space, LV_TXT_FLAG_NONE); arrow_style->text.line_space, LV_TXT_FLAG_NONE);
lv_draw_label(&header_area, mask, arrow_style, opa_scale, SYMBOL_RIGHT, LV_TXT_FLAG_NONE, NULL); lv_draw_label(&header_area, mask, arrow_style, opa_scale, SYMBOL_RIGHT, LV_TXT_FLAG_NONE, NULL);

View File

@ -16,6 +16,7 @@
#include "../lv_themes/lv_theme.h" #include "../lv_themes/lv_theme.h"
#include "../lv_misc/lv_symbol_def.h" #include "../lv_misc/lv_symbol_def.h"
#include "../lv_misc/lv_anim.h" #include "../lv_misc/lv_anim.h"
#include <strings.h>
/********************* /*********************
* DEFINES * DEFINES
@ -579,7 +580,7 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * mask, lv_desig
new_style.text.opa = sel_style->text.opa; new_style.text.opa = sel_style->text.opa;
lv_area_t area_arrow; lv_area_t area_arrow;
area_arrow.x2 = ddlist->coords.x2 - style->body.padding.hor; area_arrow.x2 = ddlist->coords.x2 - style->body.padding.hor;
area_arrow.x1 = area_arrow.x2 - lv_txt_get_width(SYMBOL_DOWN, 1, sel_style->text.font, 0, 0); area_arrow.x1 = area_arrow.x2 - lv_txt_get_width(strlen(SYMBOL_DOWN), 1, sel_style->text.font, 0, 0);
area_arrow.y1 = ddlist->coords.y1 + style->text.line_space; area_arrow.y1 = ddlist->coords.y1 + style->text.line_space;
area_arrow.y2 = area_arrow.y1 + font_h; area_arrow.y2 = area_arrow.y1 + font_h;

View File

@ -440,22 +440,32 @@ void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t index, lv_point_t
} }
/*If the last character is line break then go to the next line*/ /*If the last character is line break then go to the next line*/
if((txt[index - 1] == '\n' || txt[index - 1] == '\r') && txt[index] == '\0') { if(index > 0) {
y += letter_height + style->text.line_space; if((txt[index - 1] == '\n' || txt[index - 1] == '\r') && txt[index] == '\0') {
line_start = index; y += letter_height + style->text.line_space;
line_start = index;
}
} }
/*Calculate the x coordinate*/ /*Calculate the x coordinate*/
lv_coord_t x = lv_txt_get_width(&txt[line_start], new_line_start - line_start, lv_coord_t x = lv_txt_get_width(&txt[line_start], index - line_start,
font, style->text.letter_space, flag); font, style->text.letter_space, flag);
if(index != line_start) x += style->text.letter_space;
if(ext->align == LV_LABEL_ALIGN_CENTER) { if(ext->align == LV_LABEL_ALIGN_CENTER) {
x += lv_obj_get_width(label) / 2 - x / 2; 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) / 2 - line_w / 2;
} else if(ext->align == LV_LABEL_ALIGN_RIGHT) { } else if(ext->align == LV_LABEL_ALIGN_RIGHT) {
x += lv_obj_get_width(label) - x; 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;
} }

View File

@ -1281,7 +1281,7 @@ static void refr_cursor_area(lv_obj_t * ta)
lv_label_get_letter_pos(ext->label, cur_pos, &letter_pos); lv_label_get_letter_pos(ext->label, cur_pos, &letter_pos);
/*If the cursor is out of the text (most right) draw it to the next line*/ /*If the cursor is out of the text (most right) draw it to the next line*/
if(letter_pos.x + ext->label->coords.x1 + letter_w > ext->label->coords.x2 && ext->one_line == 0) { if(letter_pos.x + ext->label->coords.x1 + letter_w > ext->label->coords.x2 && ext->one_line == 0 && lv_label_get_align(ext->label) != LV_LABEL_ALIGN_RIGHT) {
letter_pos.x = 0; letter_pos.x = 0;
letter_pos.y += letter_h + label_style->text.line_space; letter_pos.y += letter_h + label_style->text.line_space;