draw...line & get...width
This commit is contained in:
parent
b6d6acd933
commit
a5f30a5f10
|
@ -658,6 +658,7 @@ uint8_t u8g2_IsGlyph(u8g2_t *u8g2, uint16_t requested_encoding)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* side effect: updates u8g2->font_decode */
|
||||
int8_t u8g2_GetGlyphWidth(u8g2_t *u8g2, uint16_t requested_encoding)
|
||||
{
|
||||
const uint8_t *glyph_data = u8g2_font_get_glyph_data(u8g2, requested_encoding);
|
||||
|
@ -672,6 +673,8 @@ int8_t u8g2_GetGlyphWidth(u8g2_t *u8g2, uint16_t requested_encoding)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
set one of:
|
||||
U8G2_FONT_MODE_TRANSPARENT
|
||||
|
@ -943,12 +946,14 @@ static u8g2_uint_t u8g2_string_width(u8g2_t *u8g2, const char *str) U8G2_NOINLIN
|
|||
static u8g2_uint_t u8g2_string_width(u8g2_t *u8g2, const char *str)
|
||||
{
|
||||
uint16_t e;
|
||||
u8g2_uint_t w;
|
||||
u8g2_uint_t w, dx, pw;
|
||||
|
||||
u8x8_utf8_init(u8g2_GetU8x8(u8g2));
|
||||
|
||||
/* reset the total width to zero, this will be expanded during calculation */
|
||||
w = 0;
|
||||
dx = 0;
|
||||
pw = 0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
|
@ -958,9 +963,16 @@ static u8g2_uint_t u8g2_string_width(u8g2_t *u8g2, const char *str)
|
|||
str++;
|
||||
if ( e != 0x0fffe )
|
||||
{
|
||||
w += u8g2_GetGlyphWidth(u8g2, e);
|
||||
dx = u8g2_GetGlyphWidth(u8g2, e); /* delta x value of the glyph */
|
||||
w += dx;
|
||||
pw = u8g2->font_decode.glyph_width; /* the real pixel width of the glyph */
|
||||
}
|
||||
}
|
||||
|
||||
/* adjust the last glyph */
|
||||
w -= dx;
|
||||
w += pw;
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
void u8g2_DrawUTF8Line(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, const char *s, uint8_t border_size, uint8_t is_invert)
|
||||
{
|
||||
u8g2_uint_t d, str_width;
|
||||
u8g2_uint_t fx, fy, fw, fh;
|
||||
|
||||
/* only horizontal strings are supported, so force this here */
|
||||
u8g2_SetFontDirection(u8g2, 0);
|
||||
|
@ -68,7 +69,17 @@ void u8g2_DrawUTF8Line(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w
|
|||
d -=str_width;
|
||||
d /= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
w = str_width;
|
||||
}
|
||||
|
||||
/* caluclate frame */
|
||||
fx = x-1; /* -1 adjustment so that the frame is outside */
|
||||
fy = y - u8g2_GetAscent(u8g2) - 1;
|
||||
fw = w+2; /* +2 to make the frame outside */
|
||||
fh = u8g2_GetAscent(u8g2) - u8g2_GetDescent(u8g2) + 2;
|
||||
u8g2_DrawFrame(u8g2, fx, fy, fw, fh );
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -21,7 +21,7 @@ int main(void)
|
|||
u8g2_FirstPage(&u8g2);
|
||||
do
|
||||
{
|
||||
u8g2_DrawUTF8Line(&u8g2, 5, 15, 40, "abc", 1,0);
|
||||
u8g2_DrawUTF8Line(&u8g2, 5, 15, 10, "Agile", 1,0);
|
||||
} while( u8g2_NextPage(&u8g2) );
|
||||
|
||||
utf8_show();
|
||||
|
|
Loading…
Reference in New Issue