Rename margin to padding

This commit is contained in:
Midgard 2022-09-07 21:12:46 +02:00
parent d453400ee6
commit 2610fb1cf2
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -17,7 +17,7 @@
#define STR_EQUAL 0
#define DEFAULT_BORDER_RADIUS 15
#define DEFAULT_MARGIN 10
#define DEFAULT_PADDING 10
#define DEFAULT_WIDTH 256
#define DEFAULT_HEIGHT 256
#define DEFAULT_FONT "Fira Sans 17"
@ -111,7 +111,7 @@ struct user_request {
int border_radius;
int width;
int height;
int margin;
int padding;
};
struct client_state {
@ -196,8 +196,8 @@ draw_frame(struct client_state *state, const int width, const int height)
/* Set transformations to fit image in box */
int img_width = cairo_image_surface_get_width(cairo_png_surface);
int img_height = cairo_image_surface_get_height(cairo_png_surface);
double width_scale = ((double)width - 2*state->user_request.margin) / img_width;
double height_scale = (((double)height - 2*state->user_request.margin) * 3 / 4.0) / img_height;
double width_scale = ((double)width - 2*state->user_request.padding) / img_width;
double height_scale = (((double)height - 2*state->user_request.padding) * 3 / 4.0) / img_height;
double scale = MIN(width_scale, height_scale);
if (scale > 1.0) scale = 1.0;
cairo_translate(cairo,
@ -216,7 +216,7 @@ draw_frame(struct client_state *state, const int width, const int height)
PangoLayout *layout = pango_cairo_create_layout(cairo);
pango_layout_set_text(layout, state->user_request.text, -1);
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
pango_layout_set_width(layout, (width - 2*state->user_request.margin) * PANGO_SCALE);
pango_layout_set_width(layout, (width - 2*state->user_request.padding) * PANGO_SCALE);
PangoFontDescription *desc = pango_font_description_from_string(
state->user_request.font != NULL ? state->user_request.font : DEFAULT_FONT);
pango_layout_set_font_description(layout, desc);
@ -224,7 +224,7 @@ draw_frame(struct client_state *state, const int width, const int height)
set_source_argb_cairo(cairo, &state->user_request.text_color);
int text_width = 0, text_height = 0;
pango_layout_get_size(layout, &text_width, &text_height);
cairo_move_to(cairo, state->user_request.margin, 3*height/4.0);
cairo_move_to(cairo, state->user_request.padding, 3*height/4.0);
pango_cairo_show_layout(cairo, layout);
g_object_unref(layout);
}
@ -286,6 +286,7 @@ static const struct wl_registry_listener wl_registry_listener = {
.global_remove = registry_global_remove,
};
static void
parse_hex(char *hex, struct color_argb *result_color) {
if (strlen(hex) != 4 * 2) {
@ -315,10 +316,10 @@ print_usage()
" --font=<str> Set font of text (default " DEFAULT_FONT ")\n"
" --width=<int> \n"
" --height=<int> Set width and height (default %d×%d)\n"
" --height=<int> Set margin around image and text (default %d)\n",
" --padding=<int> Set padding around image and text (default %d)\n",
DEFAULT_BORDER_RADIUS,
DEFAULT_WIDTH, DEFAULT_HEIGHT,
DEFAULT_MARGIN);
DEFAULT_PADDING);
}
int
@ -330,7 +331,7 @@ main(int argc, char *argv[])
state.user_request.backdrop = DEFAULT_BACKDROP_COLOR;
state.user_request.width = DEFAULT_WIDTH;
state.user_request.height = DEFAULT_HEIGHT;
state.user_request.margin = DEFAULT_MARGIN;
state.user_request.padding = DEFAULT_PADDING;
int c;
@ -345,7 +346,7 @@ main(int argc, char *argv[])
{"font", required_argument, 0, 0 },
{"width", required_argument, 0, 0 },
{"height", required_argument, 0, 0 },
{"margin", required_argument, 0, 0 },
{"padding", required_argument, 0, 0 },
{0, 0, 0, 0 }
};
@ -362,7 +363,7 @@ main(int argc, char *argv[])
case 5: state.user_request.font = strdup(optarg); break;
case 6: state.user_request.width = atoi(optarg); break;
case 7: state.user_request.height = atoi(optarg); break;
case 8: state.user_request.margin = atoi(optarg); break;
case 8: state.user_request.padding = atoi(optarg); break;
default: break;
}
break;