diff options
author | Phil Jones <philj56@gmail.com> | 2022-06-25 11:28:23 +0100 |
---|---|---|
committer | Phil Jones <philj56@gmail.com> | 2022-06-25 11:28:23 +0100 |
commit | eacb7c80619dd0c2d8bf601215374f64779373b6 (patch) | |
tree | 57a06bd217edbe869a92c49df94579f5f470fec2 /src | |
parent | b70772372ef51a64dece064aaa0e25e0a83354fd (diff) |
Fix padding and split into top/bottom/left/right.
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 24 | ||||
-rw-r--r-- | src/entry.c | 35 | ||||
-rw-r--r-- | src/entry.h | 17 | ||||
-rw-r--r-- | src/entry_backend/harfbuzz.c | 4 | ||||
-rw-r--r-- | src/entry_backend/pango.c | 4 | ||||
-rw-r--r-- | src/main.c | 33 |
6 files changed, 58 insertions, 59 deletions
diff --git a/src/config.c b/src/config.c index 400c73f..ba5a41c 100644 --- a/src/config.c +++ b/src/config.c @@ -237,10 +237,6 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const tofi->window.entry.background_color = parse_color(filename, lineno, value, &err); } else if (strcasecmp(option, "corner-radius") == 0) { tofi->window.entry.corner_radius = parse_uint32(filename, lineno, value, &err); - } else if (strcasecmp(option, "entry-padding") == 0) { - tofi->window.entry.padding = parse_uint32(filename, lineno, value, &err); - } else if (strcasecmp(option, "entry-color") == 0) { - tofi->window.entry.background_color = parse_color(filename, lineno, value, &err); } else if (strcasecmp(option, "font-name") == 0) { snprintf(tofi->window.entry.font_name, N_ELEM(tofi->window.entry.font_name), "%s", value); } else if (strcasecmp(option, "font-size") == 0) { @@ -248,19 +244,19 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const } else if (strcasecmp(option, "num-results") == 0) { tofi->window.entry.num_results = parse_uint32(filename, lineno, value, &err); } else if (strcasecmp(option, "outline-width") == 0) { - tofi->window.entry.border.outline_width = parse_uint32(filename, lineno, value, &err); + tofi->window.entry.outline_width = parse_uint32(filename, lineno, value, &err); } else if (strcasecmp(option, "outline-color") == 0) { - tofi->window.entry.border.outline_color = parse_color(filename, lineno, value, &err); + tofi->window.entry.outline_color = parse_color(filename, lineno, value, &err); } else if (strcasecmp(option, "prompt-text") == 0) { snprintf(tofi->window.entry.prompt_text, N_ELEM(tofi->window.entry.prompt_text), "%s", value); } else if (strcasecmp(option, "min-input-width") == 0) { tofi->window.entry.input_width = parse_uint32(filename, lineno, value, &err); - } else if (strcasecmp(option, "result-padding") == 0) { - tofi->window.entry.result_padding = parse_int32(filename, lineno, value, &err); + } else if (strcasecmp(option, "result-spacing") == 0) { + tofi->window.entry.result_spacing = parse_int32(filename, lineno, value, &err); } else if (strcasecmp(option, "border-width") == 0) { - tofi->window.entry.border.width = parse_uint32(filename, lineno, value, &err); + tofi->window.entry.border_width = parse_uint32(filename, lineno, value, &err); } else if (strcasecmp(option, "border-color") == 0) { - tofi->window.entry.border.color = parse_color(filename, lineno, value, &err); + tofi->window.entry.border_color = parse_color(filename, lineno, value, &err); } else if (strcasecmp(option, "text-color") == 0) { tofi->window.entry.foreground_color = parse_color(filename, lineno, value, &err); } else if (strcasecmp(option, "selection-color") == 0) { @@ -277,6 +273,14 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const tofi->window.margin_left = parse_uint32_percent(filename, lineno, value, &err, tofi->output_width); } else if (strcasecmp(option, "margin-right") == 0) { tofi->window.margin_right = parse_uint32_percent(filename, lineno, value, &err, tofi->output_width); + } else if (strcasecmp(option, "padding-top") == 0) { + tofi->window.entry.padding_top = parse_uint32_percent(filename, lineno, value, &err, tofi->output_height); + } else if (strcasecmp(option, "padding-bottom") == 0) { + tofi->window.entry.padding_bottom = parse_uint32_percent(filename, lineno, value, &err, tofi->output_height); + } else if (strcasecmp(option, "padding-left") == 0) { + tofi->window.entry.padding_left = parse_uint32_percent(filename, lineno, value, &err, tofi->output_width); + } else if (strcasecmp(option, "padding-right") == 0) { + tofi->window.entry.padding_right = parse_uint32_percent(filename, lineno, value, &err, tofi->output_width); } else if (strcasecmp(option, "horizontal") == 0) { tofi->window.entry.horizontal = parse_bool(filename, lineno, value, &err); } else if (strcasecmp(option, "hide-cursor") == 0) { diff --git a/src/entry.c b/src/entry.c index 9298ce8..133a706 100644 --- a/src/entry.c +++ b/src/entry.c @@ -73,21 +73,21 @@ void entry_init(struct entry *entry, uint8_t *restrict buffer, uint32_t width, u cairo_restore(cr); /* Draw the border with outlines */ - cairo_set_line_width(cr, 4 * entry->border.outline_width + 2 * entry->border.width); + cairo_set_line_width(cr, 4 * entry->outline_width + 2 * entry->border_width); rounded_rectangle(cr, width, height, entry->corner_radius); - color = entry->border.outline_color; + color = entry->outline_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); cairo_stroke_preserve(cr); - color = entry->border.color; + color = entry->border_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); - cairo_set_line_width(cr, 2 * entry->border.outline_width + 2 * entry->border.width); + cairo_set_line_width(cr, 2 * entry->outline_width + 2 * entry->border_width); cairo_stroke_preserve(cr); - color = entry->border.outline_color; + color = entry->outline_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); - cairo_set_line_width(cr, 2 * entry->border.outline_width); + cairo_set_line_width(cr, 2 * entry->outline_width); cairo_stroke_preserve(cr); /* Clear the overdrawn bits outside of the rounded corners */ @@ -100,17 +100,14 @@ void entry_init(struct entry *entry, uint8_t *restrict buffer, uint32_t width, u cairo_restore(cr); - /* Move and clip following draws to be within this outline */ - double dx = 2.0 * entry->border.outline_width + entry->border.width + entry->padding; - cairo_translate(cr, dx, dx); - width -= 2 * dx; - height -= 2 * dx; + /* Move and clip following draws to be within this outline + padding */ + double dx = 2.0 * entry->outline_width + entry->border_width; + cairo_translate(cr, dx + entry->padding_left, dx + entry->padding_top); + width -= 2 * dx + entry->padding_left + entry->padding_right; + height -= 2 * dx + entry->padding_top + entry->padding_bottom; /* Account for rounded corners */ - double inner_radius = (double)entry->corner_radius - - 2.0 * entry->border.outline_width - - entry->border.width - - entry->padding; + double inner_radius = (double)entry->corner_radius - dx; inner_radius = MAX(inner_radius, 0); dx = ceil(inner_radius * (1.0 - 1.0 / M_SQRT2)); @@ -120,14 +117,6 @@ void entry_init(struct entry *entry, uint8_t *restrict buffer, uint32_t width, u cairo_rectangle(cr, 0, 0, width, height); cairo_clip(cr); - /* Move and clip following draws to be within the specified padding */ - dx = entry->padding; - cairo_translate(cr, dx, dx); - width -= 2 * dx; - height -= 2 * dx; - cairo_rectangle(cr, 0, 0, width, height); - cairo_clip(cr); - /* Setup the backend. */ if (access(entry->font_name, R_OK) != 0) { /* diff --git a/src/entry.h b/src/entry.h index f59411f..5fa29c4 100644 --- a/src/entry.h +++ b/src/entry.h @@ -41,22 +41,23 @@ struct entry { /* Options */ bool horizontal; uint32_t num_results; + int32_t result_spacing; uint32_t font_size; char font_name[MAX_FONT_NAME_LENGTH]; char prompt_text[MAX_PROMPT_LENGTH]; uint32_t corner_radius; - uint32_t padding; + uint32_t padding_top; + uint32_t padding_bottom; + uint32_t padding_left; + uint32_t padding_right; uint32_t input_width; - int32_t result_padding; + uint32_t border_width; + uint32_t outline_width; struct color foreground_color; struct color background_color; struct color selection_color; - struct { - struct color color; - struct color outline_color; - uint32_t width; - uint32_t outline_width; - } border; + struct color border_color; + struct color outline_color; }; void entry_init(struct entry *entry, uint8_t *restrict buffer, uint32_t width, uint32_t height); diff --git a/src/entry_backend/harfbuzz.c b/src/entry_backend/harfbuzz.c index fff4950..ed15e82 100644 --- a/src/entry_backend/harfbuzz.c +++ b/src/entry_backend/harfbuzz.c @@ -210,9 +210,9 @@ void entry_backend_harfbuzz_update(struct entry *entry) /* Render our results entry text */ for (size_t i = 0; i < entry->num_results && i < entry->results.count; i++) { if (entry->horizontal) { - cairo_translate(cr, width + entry->result_padding, 0); + cairo_translate(cr, width + entry->result_spacing, 0); } else { - cairo_translate(cr, 0, font_extents.height + entry->result_padding); + cairo_translate(cr, 0, font_extents.height + entry->result_spacing); } hb_buffer_clear_contents(buffer); diff --git a/src/entry_backend/pango.c b/src/entry_backend/pango.c index 084d34f..cc2a361 100644 --- a/src/entry_backend/pango.c +++ b/src/entry_backend/pango.c @@ -70,9 +70,9 @@ void entry_backend_pango_update(struct entry *entry) for (size_t i = 0; i < entry->num_results && i < entry->results.count; i++) { if (entry->horizontal) { - cairo_translate(cr, (int)(width / PANGO_SCALE) + entry->result_padding, 0); + cairo_translate(cr, (int)(width / PANGO_SCALE) + entry->result_spacing, 0); } else { - cairo_translate(cr, 0, (int)(height / PANGO_SCALE) + entry->result_padding); + cairo_translate(cr, 0, (int)(height / PANGO_SCALE) + entry->result_spacing); } const char *str; if (i < entry->results.count) { @@ -568,13 +568,11 @@ static void usage() " --outline-color <color> Color of the border outlines.\n" " --border-width <px> Width of the border.\n" " --border-color <color> Color of the border.\n" -" --entry-padding <px> Padding around the entry box.\n" -" --entry-color <color> Color of the entry box.\n" " --text-color <color> Color of text.\n" " --prompt-text <string> Prompt text.\n" " --num-results <n> Maximum number of results to display.\n" " --selection-color <color> Color of selected result.\n" -" --result-padding <px> Spacing between results. Can be negative.\n" +" --result-spacing <px> Spacing between results. Can be negative.\n" " --min-input-width <px> Minimum width of input in horizontal mode.\n" " --width <px|%> Width of the window.\n" " --height <px|%> Height of the window.\n" @@ -583,6 +581,10 @@ static void usage() " --margin-bottom <px|%> Offset from bottom of screen.\n" " --margin-left <px|%> Offset from left of screen.\n" " --margin-right <px|%> Offset from right of screen.\n" +" --padding-top <px|%> Padding between top border and text.\n" +" --padding-bottom <px|%> Padding between bottom border and text.\n" +" --padding-left <px|%> Padding between left border and text.\n" +" --padding-right <px|%> Padding between right border and text.\n" " --hide-cursor <true|false> Hide the cursor.\n" " --horizontal <true|false> List results horizontally.\n" " --history <true|false> Sort results by number of usages.\n" @@ -598,8 +600,6 @@ static void parse_args(struct tofi *tofi, int argc, char *argv[]) {"anchor", required_argument, NULL, 0}, {"background-color", required_argument, NULL, 0}, {"corner-radius", required_argument, NULL, 0}, - {"entry-padding", required_argument, NULL, 0}, - {"entry-color", required_argument, NULL, 0}, {"font-name", required_argument, NULL, 0}, {"font-size", required_argument, NULL, 0}, {"num-results", required_argument, NULL, 0}, @@ -607,7 +607,7 @@ static void parse_args(struct tofi *tofi, int argc, char *argv[]) {"outline-width", required_argument, NULL, 0}, {"outline-color", required_argument, NULL, 0}, {"prompt-text", required_argument, NULL, 0}, - {"result-padding", required_argument, NULL, 0}, + {"result-spacing", required_argument, NULL, 0}, {"min-input-width", required_argument, NULL, 0}, {"border-width", required_argument, NULL, 0}, {"border-color", required_argument, NULL, 0}, @@ -618,6 +618,10 @@ static void parse_args(struct tofi *tofi, int argc, char *argv[]) {"margin-bottom", required_argument, NULL, 0}, {"margin-left", required_argument, NULL, 0}, {"margin-right", required_argument, NULL, 0}, + {"padding-top", required_argument, NULL, 0}, + {"padding-bottom", required_argument, NULL, 0}, + {"padding-left", required_argument, NULL, 0}, + {"padding-right", required_argument, NULL, 0}, {"horizontal", required_argument, NULL, 0}, {"hide-cursor", required_argument, NULL, 0}, {"history", required_argument, NULL, 0}, @@ -693,20 +697,21 @@ int main(int argc, char *argv[]) .width = 1280, .height = 720, .entry = { - .border = { - .width = 12, - .outline_width = 4, - .color = {0.976f, 0.149f, 0.447f, 1.0f}, - .outline_color = {0.031f, 0.031f, 0.0f, 1.0f}, - }, .font_name = "Sans", .font_size = 24, .prompt_text = "run: ", .num_results = 5, - .padding = 8, + .padding_top = 8, + .padding_bottom = 8, + .padding_left = 8, + .padding_right = 8, + .border_width = 12, + .outline_width = 4, .background_color = {0.106f, 0.114f, 0.118f, 1.0f}, .foreground_color = {1.0f, 1.0f, 1.0f, 1.0f}, - .selection_color = {0.976f, 0.149f, 0.447f, 1.0f} + .selection_color = {0.976f, 0.149f, 0.447f, 1.0f}, + .border_color = {0.976f, 0.149f, 0.447f, 1.0f}, + .outline_color = {0.031f, 0.031f, 0.0f, 1.0f}, } }, .anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |