aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-03-15 01:14:03 +0100
committerFederico Angelilli <code@fedang.net>2024-03-15 01:14:03 +0100
commit7f154168bcbb6e174800b1dbe81352a31b2cd23b (patch)
tree5cecbd0e456d2330c0b65e8c170fc568aa567542 /src
parent74a29b60cdcff2906db89707c1059ee1cc840e49 (diff)
Add x and y padding to layout
Diffstat (limited to 'src')
-rw-r--r--src/button.c7
-rw-r--r--src/button.h4
-rw-r--r--src/comet.c6
-rw-r--r--src/connect.c2
-rw-r--r--src/draw.c41
-rw-r--r--src/draw.h1
6 files changed, 31 insertions, 30 deletions
diff --git a/src/button.c b/src/button.c
index 9a7df67..2a74df6 100644
--- a/src/button.c
+++ b/src/button.c
@@ -58,10 +58,11 @@ void button_group_append(Button *btn, Button *child)
CAST(btn, ButtonGroup)->children = g_list_append(CAST(btn, ButtonGroup)->children, child);
}
-void button_set_padding(Button *btn, int padding)
+void button_set_padding(Button *btn, int x_pad, int y_pad)
{
- g_assert(padding >= 0);
- btn->padding = padding;
+ g_assert(x_pad >= 0 && y_pad >= 0);
+ btn->x_pad = x_pad;
+ btn->y_pad = y_pad;
}
bool button_set_animation(Button *btn, Animation *anim)
diff --git a/src/button.h b/src/button.h
index 0a9b2ce..7ebf435 100644
--- a/src/button.h
+++ b/src/button.h
@@ -17,7 +17,7 @@ typedef void (* ButtonAction)(Button *btn);
struct Button {
bool simple;
- int padding;
+ int x_pad, y_pad;
PangoAlignment align;
Color color;
Color line_color;
@@ -55,7 +55,7 @@ Button *button_group_create(PangoAlignment align, Color color, Color line_color)
void button_group_append(Button *btn, Button *child);
-void button_set_padding(Button *btn, int padding);
+void button_set_padding(Button *btn, int x_pad, int y_pad);
bool button_set_animation(Button *btn, Animation *anim);
diff --git a/src/comet.c b/src/comet.c
index 3ec6bc7..ed2ea91 100644
--- a/src/comet.c
+++ b/src/comet.c
@@ -327,17 +327,17 @@ int main(int argc, char **argv)
Button *group = button_group_create(PANGO_ALIGN_LEFT, grey, line_color);
Button *child1 = button_simple_create(PANGO_ALIGN_CENTER, color, line_color);
- button_set_padding(child1, 1);
+ button_set_padding(child1, 1, 1);
button_simple_set_text(child1, g_strdup("C1"), text_color);
button_simple_set_action(child1, show_action, NULL);
Button *child2 = button_simple_create(PANGO_ALIGN_CENTER, color, line_color);
- button_set_padding(child2, 1);
+ button_set_padding(child2, 1, 1);
button_simple_set_text(child2, g_strdup("C2"), text_color);
button_simple_set_action(child2, show_action, NULL);
Button *child3 = button_simple_create(PANGO_ALIGN_CENTER, color, line_color);
- button_set_padding(child3, 1);
+ button_set_padding(child3, 1, 1);
button_simple_set_text(child3, g_strdup("C3"), text_color);
button_simple_set_action(child3, show_action, NULL);
diff --git a/src/connect.c b/src/connect.c
index f6c439b..274421b 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -102,7 +102,7 @@ static void button_action(State *state, const char *event, int x, int y)
if (action != NULL) {
// NOTE: Animations may change layout!
//Animation *anim = animation_shine_create(300 * G_TIME_SPAN_MILLISECOND);
- Animation *anim = animation_pulse_create(1000 * G_TIME_SPAN_MILLISECOND);
+ Animation *anim = animation_pulse_create(300 * G_TIME_SPAN_MILLISECOND);
if (button_set_animation(btn, anim))
state_request_animation(state);
diff --git a/src/draw.c b/src/draw.c
index 873d08e..2bdcdf2 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -36,6 +36,7 @@ Drawer *draw_create(const char *font, int height, int left_pad, int right_pad, i
return draw;
}
+// TODO: Remove this
static void compute_width(Drawer *draw, Window *win, int *width, int *height)
{
int screen_width = win->con->screen_size->width;
@@ -71,27 +72,27 @@ void draw_paint(Drawer *draw, Window *win)
cairo_push_group(cr);
- int radius = layout->height / 2;
+ int radius = (layout->height - 2 * layout->y_pad) / 2;
Color color = btn->color;
cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
cairo_new_sub_path(cr);
- cairo_arc(cr, layout->x + radius, layout->y + radius, radius, 90 * degree, 270 * degree);
- cairo_arc(cr, layout->x + layout->width - radius, layout->y + radius, radius, 270 * degree, 450 * degree);
+ cairo_arc(cr, layout->x + layout->x_pad + radius, layout->y + layout->y_pad + radius, radius, 90 * degree, 270 * degree);
+ cairo_arc(cr, layout->x + layout->width - layout->x_pad - radius, layout->y + layout->y_pad + radius, radius, 270 * degree, 450 * degree);
cairo_close_path(cr);
cairo_fill(cr);
color = btn->line_color;
cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
cairo_new_sub_path(cr);
- cairo_arc(cr, layout->x + radius, layout->y + radius, radius - line_w , 90 * degree, 270 * degree);
- cairo_arc(cr, layout->x + layout->width - radius, layout->y + radius, radius - line_w, 270 * degree, 450 * degree);
+ cairo_arc(cr, layout->x + layout->x_pad + radius, layout->y + layout->y_pad + radius, radius - line_w, 90 * degree, 270 * degree);
+ cairo_arc(cr, layout->x + layout->width - layout->x_pad - radius, layout->y + layout->y_pad + radius, radius - line_w, 270 * degree, 450 * degree);
cairo_close_path(cr);
cairo_stroke(cr);
if (btn->simple) {
- int text_x = layout->x + (layout->width / 2) - (layout->text_w / 2);
- int text_y = layout->y + (layout->height / 2) - (layout->text_h / 2);
+ int text_x = layout->x + layout->width / 2 - layout->text_w / 2;
+ int text_y = layout->y + layout->y_pad + radius - layout->text_h / 2;
color = CAST(btn, ButtonSimple)->text_color;
cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
@@ -155,7 +156,6 @@ void draw_compute_layout(Drawer *draw, Window *win, GList *btns)
g_list_free_full(draw->layouts, (GDestroyNotify)layout_destroy);
draw->layouts = NULL;
- // Remove this...
int width, height;
compute_width(draw, win, &width, &height);
@@ -178,8 +178,11 @@ void draw_compute_layout(Drawer *draw, Window *win, GList *btns)
if (prev != NULL && prev->align == btn->align) x += sep;
- layout->x = x + btn->padding;
- layout->y = btn->padding;
+ layout->x_pad = btn->x_pad;
+ layout->y_pad = btn->y_pad;
+
+ layout->x = x;
+ layout->y = 0;
draw->layouts = g_list_prepend(draw->layouts, layout);
@@ -205,8 +208,11 @@ void draw_compute_layout(Drawer *draw, Window *win, GList *btns)
Layout *child = g_malloc(sizeof(Layout));
child->btn = btn;
- child->x = x + btn->padding;
- child->y = btn->padding;
+ child->x_pad = btn->x_pad;
+ child->y_pad = btn->y_pad;
+
+ child->x = x;
+ child->y = 0;
child->pl = pango_cairo_create_layout(window_get_context(win));
layout_text(child, draw->desc, height, radius);
@@ -214,10 +220,6 @@ void draw_compute_layout(Drawer *draw, Window *win, GList *btns)
draw->layouts = g_list_prepend(draw->layouts, child);
x += child->width + line_w * 2;
-
- child->width -= 2 * btn->padding;
- child->height -= 2 * btn->padding;
-
if (it->next != NULL) x += sep;
}
@@ -227,8 +229,8 @@ void draw_compute_layout(Drawer *draw, Window *win, GList *btns)
// FIXME: Temporary solution to make the antialiasing (or the circles not overlapping correctly) problem less noticeable
- bool fix_left = CAST(g_list_first(group->children)->data, Button)->padding == 0;
- bool fix_right = CAST(g_list_last(group->children)->data, Button)->padding == 0;
+ bool fix_left = CAST(g_list_first(group->children)->data, Button)->x_pad == 0;
+ bool fix_right = CAST(g_list_last(group->children)->data, Button)->x_pad == 0;
if (fix_left) {
layout->x += 1;
@@ -255,9 +257,6 @@ void draw_compute_layout(Drawer *draw, Window *win, GList *btns)
}
x += layout->width + line_w * 2;
-
- layout->width -= 2 * btn->padding;
- layout->height -= 2 * btn->padding;
}
prev = btn;
diff --git a/src/draw.h b/src/draw.h
index 8d8a806..db56946 100644
--- a/src/draw.h
+++ b/src/draw.h
@@ -29,6 +29,7 @@ typedef struct {
int x, y;
int width, height;
int text_w, text_h;
+ int x_pad, y_pad;
PangoLayout *pl;
} Layout;