diff options
| author | Federico Angelilli <code@fedang.net> | 2024-02-11 00:21:05 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-02-11 00:21:05 +0100 |
| commit | f8b372787562aecb2a4a55b336c196f47b5c1b0c (patch) | |
| tree | 08edce1bd88acdad6b9f2519fa901d359078e44d | |
| parent | f459a5088528ecd0a19716ce5a4432c8a86a994a (diff) | |
Use updated text in draw
There is a caveat: The text should always have the same size and layout as the original one for which the pango layout was calculated
| -rw-r--r-- | src/button.c | 1 | ||||
| -rw-r--r-- | src/draw.c | 4 | ||||
| -rw-r--r-- | src/state.c | 5 | ||||
| -rw-r--r-- | src/state.h | 2 |
4 files changed, 11 insertions, 1 deletions
diff --git a/src/button.c b/src/button.c index 24eaf0c..7bee576 100644 --- a/src/button.c +++ b/src/button.c @@ -9,6 +9,7 @@ Button *button_simple_create(PangoAlignment align, Color color, Color line_color btn->align = align; btn->color = color; btn->line_color = line_color; + CAST(btn, ButtonSimple)->action = NULL; return btn; } @@ -104,6 +104,8 @@ void draw_paint(Drawable *draw, Window *win) cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); cairo_move_to(cr, text_x, text_y); + // NOTE: This works only if the text didn't change in size after the layouting + pango_layout_set_text(layout->pl, CAST(layout->btn, ButtonSimple)->text, -1); pango_cairo_update_layout(cr, layout->pl); pango_cairo_show_layout(cr, layout->pl); } @@ -213,7 +215,7 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) child->btn = btn; child->x = x + btn->padding; - child->y = btn->padding;; + child->y = btn->padding; child->pl = pango_cairo_create_layout(window_get_context(win)); layout_text(child, draw->desc, scale, height, radius); diff --git a/src/state.c b/src/state.c index 0debb1f..e8ddbe0 100644 --- a/src/state.c +++ b/src/state.c @@ -21,6 +21,11 @@ void state_add_button(State *state, Button *btn) state->btns = g_list_append(state->btns, btn); } +void state_remove_button(State *state, Button *btn) +{ + state->btns = g_list_remove(state->btns, btn); +} + static gboolean redraw_and_layout(gpointer data) { State *state = data; diff --git a/src/state.h b/src/state.h index 5814415..1dedd8e 100644 --- a/src/state.h +++ b/src/state.h @@ -20,6 +20,8 @@ State *state_create(Window *win, Drawable *draw); void state_add_button(State *state, Button *btn); +void state_remove_button(State *state, Button *btn); + void state_redraw(State *state, bool changed_layout); void state_destroy(State *state); |
