aboutsummaryrefslogtreecommitdiffstats
path: root/src/wins.c
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2018-12-29 22:32:59 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2019-05-22 01:56:59 -0400
commit576994de00fd61b4ce521360cfdb076e9a051ee2 (patch)
tree2b63733426ce4cb31d00a9266154c35a628244dc /src/wins.c
parent52d52208c879c63f5e33fb4f743014b8585dc05a (diff)
downloadcalcurse-576994de00fd61b4ce521360cfdb076e9a051ee2.tar.gz
calcurse-576994de00fd61b4ce521360cfdb076e9a051ee2.zip
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>
Diffstat (limited to 'src/wins.c')
-rw-r--r--src/wins.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/wins.c b/src/wins.c
index bb08f08..0cc7ff7 100644
--- a/src/wins.c
+++ b/src/wins.c
@@ -315,14 +315,25 @@ void wins_scrollwin_resize(struct scrollwin *sw, int y, int x, int h, int w)
delwin(sw->win);
sw->win = newwin(h, w, y, x);
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;
+ 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. */
@@ -404,12 +415,6 @@ void wins_scrollwin_down(struct scrollwin *sw, int amount)
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)
{
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;
}
-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)
{
wins_get_config();