Improve scroll window pad

A scroll window consists of a pad to write on, and a window through
which to view the pad, the viewport. The pad may change in size when new
contents are loaded into the scroll window. If so, the pad size is set
with wins_scrollwin_set_linecount(). But the offset into the pad (the
top line to be displayed in the viewport) is not adjusted, although it
may not be appropriate for the new pad size. The same is the case when a
scroll window is resized and the viewport changes size. This is probably
the cause of the problem solved by commit 0b46ad4, Avoid blank space
after the last list box item, and the fix has been removed.

The wins_scrollwin_set_linecount() has been renamed
wins_scrollwin_set_pad() and sets size as well as offset. The offset is
only changed if necessary.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lars Henriksen 2018-12-29 22:32:59 +01:00 committed by Lukas Fleischer
parent 52d52208c8
commit 576994de00
4 changed files with 16 additions and 24 deletions

View File

@ -1265,15 +1265,13 @@ void wins_slctd_next(void);
void wins_init(void); void wins_init(void);
void wins_scrollwin_init(struct scrollwin *, int, int, int, int, const char *); void wins_scrollwin_init(struct scrollwin *, int, int, int, int, const char *);
void wins_scrollwin_resize(struct scrollwin *, int, int, int, int); void wins_scrollwin_resize(struct scrollwin *, int, int, int, int);
void wins_scrollwin_set_linecount(struct scrollwin *, unsigned); void wins_scrollwin_set_pad(struct scrollwin *, unsigned);
void wins_scrollwin_delete(struct scrollwin *); void wins_scrollwin_delete(struct scrollwin *);
void wins_scrollwin_draw_deco(struct scrollwin *, int); void wins_scrollwin_draw_deco(struct scrollwin *, int);
void wins_scrollwin_display(struct scrollwin *, int); void wins_scrollwin_display(struct scrollwin *, int);
void wins_scrollwin_up(struct scrollwin *, int); void wins_scrollwin_up(struct scrollwin *, int);
void wins_scrollwin_down(struct scrollwin *, int); void wins_scrollwin_down(struct scrollwin *, int);
int wins_scrollwin_is_visible(struct scrollwin *, unsigned);
void wins_scrollwin_ensure_visible(struct scrollwin *, unsigned); void wins_scrollwin_ensure_visible(struct scrollwin *, unsigned);
void wins_scrollwin_set_lower(struct scrollwin *, unsigned);
void wins_resize(void); void wins_resize(void);
void wins_resize_panels(void); void wins_resize_panels(void);
void wins_show(WINDOW *, const char *); void wins_show(WINDOW *, const char *);

View File

@ -980,7 +980,7 @@ void custom_keys_config(void)
clear(); clear();
nbdisplayed = ((notify_bar() ? row - 3 : row - 2) - LABELLINES) / LINESPERKEY; nbdisplayed = ((notify_bar() ? row - 3 : row - 2) - LABELLINES) / LINESPERKEY;
wins_scrollwin_init(&kwin, 0, 0, notify_bar() ? row - 3 : row - 2, col, _("keys configuration")); wins_scrollwin_init(&kwin, 0, 0, notify_bar() ? row - 3 : row - 2, col, _("keys configuration"));
wins_scrollwin_set_linecount(&kwin, NBKEYS * LINESPERKEY); wins_scrollwin_set_pad(&kwin, NBKEYS * LINESPERKEY);
wins_scrollwin_draw_deco(&kwin, 0); wins_scrollwin_draw_deco(&kwin, 0);
custom_keys_config_bar(); custom_keys_config_bar();
selrow = selelm = 0; selrow = selelm = 0;

View File

@ -62,7 +62,6 @@ void listbox_delete(struct listbox *lb)
static void listbox_fix_visible_region(struct listbox *lb) static void listbox_fix_visible_region(struct listbox *lb)
{ {
unsigned last_line = lb->ch[lb->item_count] - 1;
int i; int i;
wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[lb->item_sel]); wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[lb->item_sel]);
@ -74,9 +73,6 @@ static void listbox_fix_visible_region(struct listbox *lb)
wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[i + 1] - 1); wins_scrollwin_ensure_visible(&(lb->sw), lb->ch[i + 1] - 1);
i++; i++;
} }
if (wins_scrollwin_is_visible(&(lb->sw), last_line))
wins_scrollwin_set_lower(&(lb->sw), last_line);
} }
void listbox_resize(struct listbox *lb, int y, int x, int h, int w) void listbox_resize(struct listbox *lb, int y, int x, int h, int w)
@ -118,8 +114,7 @@ void listbox_load_items(struct listbox *lb, int item_count)
ch += lb->fn_height(i, lb->cb_data); ch += lb->fn_height(i, lb->cb_data);
} }
lb->ch[item_count] = ch; lb->ch[item_count] = ch;
wins_scrollwin_set_pad(&(lb->sw), ch);
wins_scrollwin_set_linecount(&(lb->sw), ch);
if (item_count > 0 && lb->item_sel < 0) if (item_count > 0 && lb->item_sel < 0)
lb->item_sel = 0; lb->item_sel = 0;

View File

@ -315,14 +315,25 @@ void wins_scrollwin_resize(struct scrollwin *sw, int y, int x, int h, int w)
delwin(sw->win); delwin(sw->win);
sw->win = newwin(h, w, y, x); sw->win = newwin(h, w, y, x);
sw->inner = newpad(BUFSIZ, w); sw->inner = newpad(BUFSIZ, w);
wins_scrollwin_set_pad(sw, sw->line_num);
} }
/* /*
* Set the number of lines to be displayed. * Set the number of lines (pad size) and the line offset
* (the part of the pad to be displayed in the viewport).
*/ */
void wins_scrollwin_set_linecount(struct scrollwin *sw, unsigned lines) void wins_scrollwin_set_pad(struct scrollwin *sw, unsigned lines)
{ {
int inner_h = sw->h - (conf.compact_panels ? 2 : 4);
sw->line_num = lines; sw->line_num = lines;
if (lines > inner_h) {
/* pad partly displayed in viewport */
if (sw->line_off > lines - inner_h)
/* offset too big */
sw->line_off = lines - inner_h;
} else
sw->line_off = 0;
} }
/* Free an already created scrollwin. */ /* Free an already created scrollwin. */
@ -404,12 +415,6 @@ void wins_scrollwin_down(struct scrollwin *sw, int amount)
sw->line_off = sw->line_num - inner_h; sw->line_off = sw->line_num - inner_h;
} }
int wins_scrollwin_is_visible(struct scrollwin *sw, unsigned line)
{
int inner_h = sw->h - (conf.compact_panels ? 2 : 4);
return ((line >= sw->line_off) && (line < sw->line_off + inner_h));
}
void wins_scrollwin_ensure_visible(struct scrollwin *sw, unsigned line) void wins_scrollwin_ensure_visible(struct scrollwin *sw, unsigned line)
{ {
int inner_h = sw->h - (conf.compact_panels ? 2 : 4); int inner_h = sw->h - (conf.compact_panels ? 2 : 4);
@ -420,12 +425,6 @@ void wins_scrollwin_ensure_visible(struct scrollwin *sw, unsigned line)
sw->line_off = line - inner_h + 1; sw->line_off = line - inner_h + 1;
} }
void wins_scrollwin_set_lower(struct scrollwin *sw, unsigned line)
{
int inner_h = sw->h - (conf.compact_panels ? 2 : 4);
sw->line_off = MAX((int)line - inner_h + 1, 0);
}
void wins_resize_panels(void) void wins_resize_panels(void)
{ {
wins_get_config(); wins_get_config();