aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-03-16 21:11:51 +0100
committerFederico Angelilli <code@fedang.net>2024-03-16 21:11:51 +0100
commit7d8a85532b8ee97af9568443fd97e9701943b225 (patch)
tree7184361d47d2856be20f21ebb256f97f0f61818f
parent4794a57face4e6e521c8a60a120ebf00bbc8a94f (diff)
Add min and max button width
-rw-r--r--src/button.c8
-rw-r--r--src/button.h4
-rw-r--r--src/draw.c10
3 files changed, 22 insertions, 0 deletions
diff --git a/src/button.c b/src/button.c
index 3b61bd2..9d869dc 100644
--- a/src/button.c
+++ b/src/button.c
@@ -78,6 +78,14 @@ void button_set_line(Button *btn, Color line_color, int line_width)
btn->line_width = line_width;
}
+void button_set_width(Button *btn, int max, int min)
+{
+ g_assert(max >= min);
+ g_assert(max >= 0 && min >= 0);
+ btn->max_width = max;
+ btn->min_width = min;
+}
+
void button_destroy(Button *btn)
{
animation_destroy(btn->anim);
diff --git a/src/button.h b/src/button.h
index d1516fc..a87d3e8 100644
--- a/src/button.h
+++ b/src/button.h
@@ -23,6 +23,8 @@ struct Button {
Color color;
Color line_color;
int line_width;
+ int max_width;
+ int min_width;
Animation *anim;
};
@@ -63,6 +65,8 @@ bool button_set_animation(Button *btn, Animation *anim);
void button_set_line(Button *btn, Color line_color, int line_width);
+void button_set_width(Button *btn, int max, int min);
+
void button_destroy(Button *btn);
#endif
diff --git a/src/draw.c b/src/draw.c
index 5a43a51..51a8a59 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -187,6 +187,15 @@ static void compute_width(Drawer *draw, Window *win)
log_debug("Draw context width calculated [width=%d]", draw->width);
}
+static void layout_check_width(Layout *layout)
+{
+ if (layout->btn->max_width > 0)
+ layout->width = MIN(layout->btn->max_width, layout->width);
+
+ if (layout->btn->min_width > 0)
+ layout->width = MAX(layout->btn->min_width, layout->width);
+}
+
static GList *compute_group_layout(Drawer *draw, GList *btns, int bx, bool root)
{
GList *layouts = NULL;
@@ -242,6 +251,7 @@ retry:
// NOTE: We add half a line width on both sides
layout->width += layout->line_w;
+ layout_check_width(layout);
// Apply layout_func on the layout
ANIMATION(btn, layout, layout);