diff options
author | Lars Henriksen <LarsHenriksen@get2net.dk> | 2019-05-14 07:10:33 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@calcurse.org> | 2019-05-26 10:04:28 -0400 |
commit | d15f1e9242f77d9021af8c4b45eec96eb82a8eb6 (patch) | |
tree | 82576fecf3b52d08cc6b8d99925ce017c4e1615d /src | |
parent | 4db9677119f412fd38440e5591afbfb631a11b3d (diff) | |
download | calcurse-d15f1e9242f77d9021af8c4b45eec96eb82a8eb6.tar.gz calcurse-d15f1e9242f77d9021af8c4b45eec96eb82a8eb6.zip |
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 <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 2 | ||||
-rw-r--r-- | src/custom.c | 14 | ||||
-rw-r--r-- | src/day.c | 15 | ||||
-rw-r--r-- | src/vars.c | 2 |
4 files changed, 20 insertions, 13 deletions
diff --git a/src/config.c b/src/config.c index ce595f9..511ea80 100644 --- a/src/config.c +++ b/src/config.c @@ -115,7 +115,7 @@ static const struct confvar confmap[] = { {"general.confirmdelete", CONFIG_HANDLER_BOOL(conf.confirm_delete)}, {"general.confirmquit", CONFIG_HANDLER_BOOL(conf.confirm_quit)}, {"general.firstdayofweek", config_parse_first_day_of_week, config_serialize_first_day_of_week, NULL}, - {"general.multipledays", CONFIG_HANDLER_UNSIGNED(conf.multiple_days)}, + {"general.multipledays", CONFIG_HANDLER_BOOL(conf.multiple_days)}, {"general.periodicsave", CONFIG_HANDLER_UNSIGNED(conf.periodic_save)}, {"general.systemevents", CONFIG_HANDLER_BOOL(conf.systemevents)}, {"general.systemdialogs", CONFIG_HANDLER_BOOL(conf.system_dialogs)}, diff --git a/src/custom.c b/src/custom.c index 52ecdcd..d474d5b 100644 --- a/src/custom.c +++ b/src/custom.c @@ -643,13 +643,10 @@ static void print_general_option(int i, WINDOW *win, int y, int hilt, void *cb_d _("(insert an empty line after each appointment)")); break; case MULTIPLE_DAYS: - custom_apply_attr(win, ATTR_HIGHEST); - mvwprintw(win, y, XPOS + strlen(opt[MULTIPLE_DAYS]), "%d", - conf.multiple_days); - custom_remove_attr(win, ATTR_HIGHEST); + print_bool_option_incolor(win, conf.multiple_days, y, + XPOS + strlen(opt[MULTIPLE_DAYS])); mvwaddstr(win, y + 1, XPOS, - _("(number of days (1..21) to display in the appointments " - "panel)")); + _("(display more than one day in the appointments panel)")); break; case AUTO_SAVE: print_bool_option_incolor(win, conf.auto_save, y, @@ -807,10 +804,7 @@ static void general_option_edit(int i) ui_todo_load_items(); break; case MULTIPLE_DAYS: - if (conf.multiple_days == 21) - conf.multiple_days = 1; - else - conf.multiple_days++; + conf.multiple_days = !conf.multiple_days; break; case HEADER_LINE: conf.header_line = !conf.header_line; @@ -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) @@ -122,7 +122,7 @@ void vars_init(void) /* Variables for user configuration */ conf.cal_view = CAL_MONTH_VIEW; conf.todo_view = TODO_HIDE_COMPLETED_VIEW; - conf.multiple_days = 7; + conf.multiple_days = 1; conf.header_line = 1; conf.event_separator = 1; conf.day_separator = 1; |