diff options
-rw-r--r-- | src/entry.c | 23 | ||||
-rw-r--r-- | src/entry_backend/harfbuzz.c | 34 | ||||
-rw-r--r-- | src/entry_backend/pango.c | 28 |
3 files changed, 52 insertions, 33 deletions
diff --git a/src/entry.c b/src/entry.c index 5ccdb72..6a55741 100644 --- a/src/entry.c +++ b/src/entry.c @@ -43,22 +43,6 @@ static void apply_text_theme_fallback(struct text_theme *theme, const struct tex } } -static void fixup_padding_sizes(struct directional *padding, uint32_t clip_width, uint32_t clip_height) -{ - if (padding->top < 0) { - padding->top = clip_height; - } - if (padding->bottom < 0) { - padding->bottom = clip_height; - } - if (padding->left < 0) { - padding->left = clip_width; - } - if (padding->right < 0) { - padding->right = clip_width; - } -} - void entry_init(struct entry *entry, uint8_t *restrict buffer, uint32_t width, uint32_t height, uint32_t scale) { entry->image.width = width; @@ -204,13 +188,6 @@ void entry_init(struct entry *entry, uint8_t *restrict buffer, uint32_t width, u apply_text_theme_fallback(&entry->alternate_result_theme, &entry->default_result_theme); apply_text_theme_fallback(&entry->selection_theme, &default_theme); - fixup_padding_sizes(&entry->prompt_theme.padding, width, height); - fixup_padding_sizes(&entry->input_theme.padding, width, height); - fixup_padding_sizes(&entry->placeholder_theme.padding, width, height); - fixup_padding_sizes(&entry->default_result_theme.padding, width, height); - fixup_padding_sizes(&entry->alternate_result_theme.padding, width, height); - fixup_padding_sizes(&entry->selection_theme.padding, width, height); - /* The cursor is a special case, as it just needs the input colours. */ if (!entry->cursor_theme.color_specified) { entry->cursor_theme.color = entry->input_theme.foreground_color; diff --git a/src/entry_backend/harfbuzz.c b/src/entry_backend/harfbuzz.c index 999e555..ae26d67 100644 --- a/src/entry_backend/harfbuzz.c +++ b/src/entry_backend/harfbuzz.c @@ -153,10 +153,11 @@ static cairo_text_extents_t render_text( */ static cairo_text_extents_t render_text_themed( cairo_t *cr, - struct entry_backend_harfbuzz *hb, + struct entry *entry, const char *text, const struct text_theme *theme) { + struct entry_backend_harfbuzz *hb = &entry->harfbuzz; cairo_font_extents_t font_extents; cairo_font_extents(cr, &font_extents); struct directional padding = theme->padding; @@ -180,6 +181,29 @@ static cairo_text_extents_t render_text_themed( return extents; } + /* + * If any of the padding values are negative, make them just big enough + * to fit the available area. This is needed over just making them + * bigger than the clip area in order to make rounded corners line up + * with the edges nicely. + */ + cairo_matrix_t mat; + cairo_get_matrix(cr, &mat); + int32_t base_x = mat.x0 - entry->clip_x + extents.x_bearing; + int32_t base_y = mat.y0 - entry->clip_y; + if (padding.left < 0) { + padding.left = base_x; + } + if (padding.right < 0) { + padding.right = entry->clip_width - extents.width - base_x; + } + if (padding.top < 0) { + padding.top = base_y; + } + if (padding.bottom < 0) { + padding.bottom = entry->clip_height - font_extents.height - base_y; + } + cairo_save(cr); color = theme->background_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); @@ -601,7 +625,7 @@ void entry_backend_harfbuzz_update(struct entry *entry) cairo_save(cr); /* Render the prompt */ - extents = render_text_themed(cr, &entry->harfbuzz, entry->prompt_text, &entry->prompt_theme); + extents = render_text_themed(cr, entry, entry->prompt_text, &entry->prompt_theme); cairo_translate(cr, extents.x_advance, 0); cairo_translate(cr, entry->prompt_padding, 0); @@ -699,7 +723,7 @@ void entry_backend_harfbuzz_update(struct entry *entry) * We're not auto-detecting how many results we * can fit, so just render the text. */ - extents = render_text_themed(cr, &entry->harfbuzz, result, theme); + extents = render_text_themed(cr, entry, result, theme); } else if (!entry->horizontal) { /* * The height of the text doesn't change, so @@ -708,7 +732,7 @@ void entry_backend_harfbuzz_update(struct entry *entry) if (size_overflows(entry, 0, font_extents.height)) { break; } else { - extents = render_text_themed(cr, &entry->harfbuzz, result, theme); + extents = render_text_themed(cr, entry, result, theme); } } else { /* @@ -720,7 +744,7 @@ void entry_backend_harfbuzz_update(struct entry *entry) * to the main canvas only if it will fit. */ cairo_push_group(cr); - extents = render_text_themed(cr, &entry->harfbuzz, result, theme); + extents = render_text_themed(cr, entry, result, theme); cairo_pattern_t *group = cairo_pop_group(cr); if (size_overflows(entry, extents.x_advance, 0)) { diff --git a/src/entry_backend/pango.c b/src/entry_backend/pango.c index d274950..2865961 100644 --- a/src/entry_backend/pango.c +++ b/src/entry_backend/pango.c @@ -34,12 +34,13 @@ static void rounded_rectangle(cairo_t *cr, uint32_t width, uint32_t height, uint static void render_text_themed( cairo_t *cr, - PangoLayout *layout, + struct entry *entry, const char *text, const struct text_theme *theme, PangoRectangle *ink_rect, PangoRectangle *logical_rect) { + PangoLayout *layout = entry->pango.layout; struct color color = theme->foreground_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); @@ -56,6 +57,23 @@ static void render_text_themed( struct directional padding = theme->padding; + cairo_matrix_t mat; + cairo_get_matrix(cr, &mat); + int32_t base_x = mat.x0 - entry->clip_x + ink_rect->x; + int32_t base_y = mat.y0 - entry->clip_y; + if (padding.left < 0) { + padding.left = base_x; + } + if (padding.right < 0) { + padding.right = entry->clip_width - ink_rect->width - base_x; + } + if (padding.top < 0) { + padding.top = base_y; + } + if (padding.bottom < 0) { + padding.bottom = entry->clip_height - logical_rect->height - base_y; + } + cairo_save(cr); color = theme->background_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); @@ -299,7 +317,7 @@ void entry_backend_pango_update(struct entry *entry) /* Render the prompt */ PangoRectangle ink_rect; PangoRectangle logical_rect; - render_text_themed(cr, layout, entry->prompt_text, &entry->prompt_theme, &ink_rect, &logical_rect); + render_text_themed(cr, entry, entry->prompt_text, &entry->prompt_theme, &ink_rect, &logical_rect); cairo_translate(cr, logical_rect.width + logical_rect.x, 0); cairo_translate(cr, entry->prompt_padding, 0); @@ -402,17 +420,17 @@ void entry_backend_pango_update(struct entry *entry) } if (entry->num_results > 0) { - render_text_themed(cr, layout, str, theme, &ink_rect, &logical_rect); + render_text_themed(cr, entry, str, theme, &ink_rect, &logical_rect); } else if (!entry->horizontal) { if (size_overflows(entry, 0, logical_rect.height)) { entry->num_results_drawn = i; break; } else { - render_text_themed(cr, layout, str, theme, &ink_rect, &logical_rect); + render_text_themed(cr, entry, str, theme, &ink_rect, &logical_rect); } } else { cairo_push_group(cr); - render_text_themed(cr, layout, str, theme, &ink_rect, &logical_rect); + render_text_themed(cr, entry, str, theme, &ink_rect, &logical_rect); cairo_pattern_t *group = cairo_pop_group(cr); if (size_overflows(entry, logical_rect.width, 0)) { |