From d15f1e9242f77d9021af8c4b45eec96eb82a8eb6 Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Tue, 14 May 2019 07:10:33 +0200 Subject: Automate the calculation of number of days to load Instead of having the user tell how many days to load, calcurse can calculate an overestimation from the running configuration (panel size, appearance of headers and separators etc.) The configuration variable conf.multiple_days is turned into a Boolean that switches the feature on and off. Signed-off-by: Lars Henriksen Signed-off-by: Lukas Fleischer --- src/day.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/day.c') diff --git a/src/day.c b/src/day.c index b556481..5bbc0a4 100644 --- a/src/day.c +++ b/src/day.c @@ -106,9 +106,22 @@ int day_sel_index(void) return -1; } +/* + * Return the number of days to load in the appointments panel. + */ int day_get_days(void) { - return conf.multiple_days; + int panel, day; + + if (!conf.multiple_days) + return 1; + + panel = win[APP].h - (conf.compact_panels ? 2 : 4); + /* Assume one event per day (no event separator). */ + day = 2 + conf.header_line + conf.day_separator + conf.empty_appt_line; + + /* Round up. */ + return panel / day + (panel % day != 0); } static void day_free(struct day_item *day) -- cgit v1.2.3-54-g00ecf