Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement directional padding #85

Merged
merged 2 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ void init_default_style(struct mako_style *style) {
style->margin.bottom = 10;
style->margin.left = 10;

style->padding = 5;
style->padding.top = 5;
style->padding.right = 5;
style->padding.bottom = 5;
style->padding.left = 5;

style->border_size = 2;

style->font = strdup("monospace 10");
Expand Down Expand Up @@ -235,7 +239,11 @@ bool apply_superset_style(
target->margin.bottom =
max(style->margin.bottom, target->margin.bottom);
target->margin.left = max(style->margin.left, target->margin.left);
target->padding = max(style->padding, target->padding);
target->padding.top = max(style->padding.top, target->padding.top);
target->padding.right = max(style->padding.right, target->padding.right);
target->padding.bottom =
max(style->padding.bottom, target->padding.bottom);
target->padding.left = max(style->padding.left, target->padding.left);
target->border_size = max(style->border_size, target->border_size);
target->default_timeout =
max(style->default_timeout, target->default_timeout);
Expand Down Expand Up @@ -336,7 +344,7 @@ static bool apply_style_option(struct mako_style *style, const char *name,
} else if (strcmp(name, "margin") == 0) {
return spec->margin = parse_directional(value, &style->margin);
} else if (strcmp(name, "padding") == 0) {
return spec->padding = parse_int(value, &style->padding);
return spec->padding = parse_directional(value, &style->padding);
} else if (strcmp(name, "border-size") == 0) {
return spec->border_size = parse_int(value, &style->border_size);
} else if (strcmp(name, "border-color") == 0) {
Expand Down
2 changes: 1 addition & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct mako_style {
int32_t width;
int32_t height;
struct mako_directional margin;
int32_t padding;
struct mako_directional padding;
int32_t border_size;

char *font;
Expand Down
13 changes: 7 additions & 6 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ static int render_notification(cairo_t *cairo, struct mako_state *state,
struct mako_style *style, const char *text, int offset_y, int scale,
struct mako_hotspot *hotspot) {
int border_size = 2 * style->border_size;
int padding_size = 2 * style->padding;
int padding_height = style->padding.top + style->padding.bottom;
int padding_width = style->padding.left + style->padding.right;

// If the compositor has forced us to shrink down, do so.
int notif_width =
Expand All @@ -91,8 +92,8 @@ static int render_notification(cairo_t *cairo, struct mako_state *state,

PangoLayout *layout = pango_cairo_create_layout(cairo);
set_layout_size(layout,
notif_width - border_size - padding_size,
style->height - border_size - padding_size,
notif_width - border_size - padding_width,
style->height - border_size - padding_height,
scale);
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
Expand Down Expand Up @@ -125,7 +126,7 @@ static int render_notification(cairo_t *cairo, struct mako_state *state,
pango_layout_get_pixel_size(layout, NULL, &buffer_text_height);
int text_height = buffer_text_height / scale;

int notif_height = border_size + padding_size + text_height;
int notif_height = border_size + padding_height + text_height;

// Render border
set_source_u32(cairo, style->colors.border);
Expand Down Expand Up @@ -153,8 +154,8 @@ static int render_notification(cairo_t *cairo, struct mako_state *state,
// Render text
set_source_u32(cairo, style->colors.text);
move_to(cairo,
offset_x + style->border_size + style->padding,
offset_y + style->border_size + style->padding,
offset_x + style->border_size + style->padding.left,
offset_y + style->border_size + style->padding.top,
scale);
pango_cairo_update_layout(cairo, layout);
pango_cairo_show_layout(cairo, layout);
Expand Down