diff options
| -rw-r--r-- | src/button.c | 2 | ||||
| -rw-r--r-- | src/comet.c | 9 | ||||
| -rw-r--r-- | src/connect.c | 2 |
3 files changed, 11 insertions, 2 deletions
diff --git a/src/button.c b/src/button.c index 9d869dc..aac4ec0 100644 --- a/src/button.c +++ b/src/button.c @@ -80,7 +80,7 @@ void button_set_line(Button *btn, Color line_color, int line_width) void button_set_width(Button *btn, int max, int min) { - g_assert(max >= min); + g_assert(max == 0 || max >= min); g_assert(max >= 0 && min >= 0); btn->max_width = max; btn->min_width = min; 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); diff --git a/src/connect.c b/src/connect.c index 1ad5c9a..3788db1 100644 --- a/src/connect.c +++ b/src/connect.c @@ -121,7 +121,7 @@ static bool button_action_find(State *state, GList *layouts, int x, int y) else animation_destroy(anim); - log_info("Triggering action for button [text=%s, button=%p]", button_simple_get_text(btn), btn); + log_info("Triggering action for button [text=\"%s\", button=%p]", button_simple_get_text(btn), btn); action(btn); return true; } |
