summaryrefslogtreecommitdiff
path: root/src/entry_backend
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2023-02-26 11:55:05 +0000
committerPhil Jones <philj56@gmail.com>2023-02-26 11:55:05 +0000
commit57d3a301b09c531972de4d012faafdc402f7b2d0 (patch)
tree3a3a49006b6748019b3761aeb146f9361c0007aa /src/entry_backend
parent68ac60509f11d3a449a317a8d9c092ac49763451 (diff)
Pad just enough when -1 is specified.
This allows rounded background corners to work when a padding of -1 is specified.
Diffstat (limited to 'src/entry_backend')
-rw-r--r--src/entry_backend/harfbuzz.c34
-rw-r--r--src/entry_backend/pango.c28
2 files changed, 52 insertions, 10 deletions
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)) {