From c89bd80db59e9f4828a9a8ce43bdf90ce1512158 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Sat, 16 Mar 2024 21:31:48 +0100 Subject: Precompute max button size --- src/comet.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/comet.c') diff --git a/src/comet.c b/src/comet.c index 1d055db..636683a 100644 --- a/src/comet.c +++ b/src/comet.c @@ -222,11 +222,17 @@ static void menu_action(Button *btn) static void register_buttons(State *state, Color color, Color text_color, Color line_color, int line_w) { + // Precompute max button size + int text_w; + draw_compute_text_size(state->draw, " 100%", &text_w, NULL); + int min_w = text_w + line_w + state->draw->height; + // Cpu usage button Button *cpu_btn = button_simple_create(PANGO_ALIGN_RIGHT, color); button_simple_set_text(cpu_btn, g_strdup(" 0%"), text_color); button_simple_set_action(cpu_btn, show_action, state); button_set_line(cpu_btn, line_color, line_w); + button_set_width(cpu_btn, 0, min_w); state_add_button(state, cpu_btn); cpu_update(cpu_btn); @@ -237,6 +243,7 @@ static void register_buttons(State *state, Color color, Color text_color, Color button_simple_set_text(temp_btn, g_strdup("temp"), text_color); button_simple_set_action(temp_btn, show_action, state); button_set_line(temp_btn, line_color, line_w); + button_set_width(temp_btn, 0, min_w); state_add_button(state, temp_btn); temp_update(temp_btn); @@ -247,6 +254,7 @@ static void register_buttons(State *state, Color color, Color text_color, Color button_simple_set_text(ram_btn, g_strdup("ram"), text_color); button_simple_set_action(ram_btn, show_action, state); button_set_line(ram_btn, line_color, line_w); + button_set_width(ram_btn, 0, min_w); state_add_button(state, ram_btn); ram_update(ram_btn); @@ -257,6 +265,7 @@ static void register_buttons(State *state, Color color, Color text_color, Color button_simple_set_text(disk_btn, g_strdup("disk"), text_color); button_simple_set_action(disk_btn, show_action, state); button_set_line(disk_btn, line_color, line_w); + button_set_width(disk_btn, 0, min_w); state_add_button(state, disk_btn); disk_update(disk_btn); -- cgit v1.2.3