toastd: Adjust spacing, try to vertically center text

This commit is contained in:
K. Lange 2021-10-29 09:43:45 +09:00
parent 7510134916
commit 9352c31487
3 changed files with 19 additions and 2 deletions

View File

@ -92,14 +92,16 @@ static void handle_msg(JSON_Value * msg) {
if (!load_sprite(&myIcon, msg_icon->string)) {
/* Is this a reasonable icon to display? */
if (myIcon.width < 100) {
textOffset = myIcon.width + 4; /* Sounds like a fine padding... */
textOffset = myIcon.width + 8; /* Sounds like a fine padding... */
draw_sprite(ctx, &myIcon, 10, (background_sprite.height - myIcon.height) / 2);
}
free(myIcon.bitmap);
}
}
markup_draw_string(ctx, 10 + textOffset, 26, msg_body->string, rgb(255,255,255));
int height = markup_string_height(msg_body->string);
markup_draw_string(ctx, 10 + textOffset, (ctx->height - height) / 2, msg_body->string, rgb(255,255,255));
yutani_flip(yctx, win);
}

View File

@ -5,6 +5,7 @@
_Begin_C_Header
int markup_string_width(const char * str);
int markup_string_height(const char * str);
int markup_draw_string(gfx_context_t * ctx, int x, int y, const char * str, uint32_t color);
void markup_text_init(void);

View File

@ -140,6 +140,20 @@ int markup_string_width(const char * str) {
return state.max_cursor_x - state.initial_left;
}
int markup_string_height(const char * str) {
struct MarkupState state = {list_create(), 0, 0, 0, 0, 0, NULL, 0, list_create()};
struct markup_state * parser = markup_init(&state, parser_open, parser_close, parser_dryrun);
while (*str) {
if (markup_parse(parser, *str++)) {
break;
}
}
markup_finish(parser);
list_free(state.state);
list_free(state.colors);
return state.cursor_y;
}
int markup_draw_string(gfx_context_t * ctx, int x, int y, const char * str, uint32_t color) {
struct MarkupState state = {list_create(), 0, x, y, x, color, ctx, x, list_create()};
struct markup_state * parser = markup_init(&state, parser_open, parser_close, parser_data);