fix: Calculate position of batt_line based on clock format

This commit is contained in:
cmacrae 2020-07-08 21:01:43 +01:00
parent 8b015b9247
commit 146f0d45f1
No known key found for this signature in database
GPG key ID: 53922D7E54A14F5D

View file

@ -262,27 +262,21 @@ void bar_refresh(struct bar *bar)
int initial_bar_right_x = bar->frame.size.width - 10;
time_t rawtime;
time(&rawtime);
float time_line_width = 0;
int time_line_pos;
struct tm *timeinfo = localtime(&rawtime);
if (timeinfo) {
char time[255];
strftime(time, sizeof(time), g_bar_manager._clock_format, timeinfo);
//snprintf(time, sizeof(time), "%02d:%02d", timeinfo->tm_hour, timeinfo->tm_min);
struct bar_line time_line = bar_prepare_line(g_bar_manager.t_font, time, g_bar_manager.foreground_color);
CGPoint t_pos = bar_align_line(bar, time_line, ALIGN_RIGHT, ALIGN_CENTER);
bar_draw_line(bar, time_line, t_pos.x, t_pos.y);
CGPoint ti_pos = bar_align_line(bar, g_bar_manager.clock_icon, 0, ALIGN_CENTER);
ti_pos.x = t_pos.x - g_bar_manager.clock_icon.bounds.size.width - 5;
CGPoint tu_pos = bar_align_line(bar, g_bar_manager.clock_underline, 0, ALIGN_BOTTOM);
tu_pos.x = tu_pos.x - g_bar_manager.clock_underline.bounds.size.width / 2 - time_line.bounds.size.width / 2 - (g_bar_manager.clock_icon.bounds.size.width + 5) / 2;
time_line_pos = ti_pos.x;
bar_draw_line(bar, g_bar_manager.clock_icon, ti_pos.x, ti_pos.y);
bar_draw_line(bar, g_bar_manager.clock_underline, tu_pos.x, tu_pos.y);
bar_destroy_line(time_line);
initial_bar_right_x = tu_pos.x - 10;
}
bool has_batt = false;
@ -294,21 +288,15 @@ void bar_refresh(struct bar *bar)
struct bar_line batt_line = bar_prepare_line(g_bar_manager.t_font, batt, g_bar_manager.foreground_color);
CGPoint p_pos = bar_align_line(bar, batt_line, ALIGN_RIGHT, ALIGN_CENTER);
p_pos.x = p_pos.x - time_line_width - g_bar_manager.clock_underline.bounds.size.width - 20;
p_pos.x = time_line_pos - 40;
bar_draw_line(bar, batt_line, p_pos.x, p_pos.y);
struct bar_line batt_icon = charging ? g_bar_manager.power_icon : g_bar_manager.battr_icon;
CGPoint pi_pos = bar_align_line(bar, batt_icon, 0, ALIGN_CENTER);
pi_pos.x = p_pos.x - batt_icon.bounds.size.width - 5;
CGPoint pu_pos = bar_align_line(bar, g_bar_manager.power_underline, 0, ALIGN_BOTTOM);
pu_pos.x = pu_pos.x - g_bar_manager.power_underline.bounds.size.width / 2 - batt_line.bounds.size.width / 2 - (batt_icon.bounds.size.width + 5) / 2;
pi_pos.x = p_pos.x - batt_icon.bounds.size.width;
bar_draw_line(bar, batt_icon, pi_pos.x, pi_pos.y);
bar_draw_line(bar, g_bar_manager.power_underline, pu_pos.x, pu_pos.y);
bar_destroy_line(batt_line);
initial_bar_right_x = pu_pos.x - 10;
}
// BAR CENTER
@ -348,7 +336,7 @@ void bar_refresh(struct bar *bar)
}
bar_draw_line(bar, title_line, pos.x, pos.y);
free_title:
free_title:
bar_destroy_line(title_line);
free(title);
}