summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2d5758c)
raw | patch | inline | side by side (parent: 2d5758c)
author | Max Kellermann <max@duempel.org> | |
Sat, 10 Oct 2009 15:45:23 +0000 (17:45 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Sat, 10 Oct 2009 15:45:23 +0000 (17:45 +0200) |
Moved code from list_window_paint(). Call it in list_window_resize(),
list_window_set_length(), list_window_set_cursor(),
list_window_move_cursor(). Now that all the modifying code has been
removed from list_window_paint(), we can pass a const object to that
function.
list_window_set_length(), list_window_set_cursor(),
list_window_move_cursor(). Now that all the modifying code has been
removed from list_window_paint(), we can pass a const object to that
function.
src/list_window.c | patch | blob | history | |
src/list_window.h | patch | blob | history |
diff --git a/src/list_window.c b/src/list_window.c
index ba2542905b4cdac993f660726aae545a762a9328..bda9f30a64954528e87cc7ca946abcaa55a61d52 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
}
}
+/**
+ * Scroll after the cursor was moved, the list was changed or the
+ * window was resized.
+ */
+static void
+list_window_check_origin(struct list_window *lw)
+{
+ int start = lw->start;
+
+ if ((unsigned) options.scroll_offset * 2 >= lw->rows)
+ // Center if the offset is more than half the screen
+ start = lw->selected - lw->rows / 2;
+ else
+ {
+ if (lw->selected < lw->start + options.scroll_offset)
+ start = lw->selected - options.scroll_offset;
+
+ if (lw->selected >= lw->start + lw->rows - options.scroll_offset)
+ {
+ start = lw->selected - lw->rows + 1 + options.scroll_offset;
+ }
+ }
+
+ if (start + lw->rows > lw->length)
+ start = lw->length - lw->rows;
+
+ if (start < 0 || lw->length == 0)
+ start = 0;
+
+ lw->start = start;
+}
+
void
list_window_resize(struct list_window *lw, unsigned width, unsigned height)
{
lw->cols = width;
lw->rows = height;
+
+ list_window_check_origin(lw);
}
void
lw->length = length;
list_window_check_selected(lw);
+ list_window_check_origin(lw);
}
void
lw->selected_end = i;
list_window_check_selected(lw);
+ list_window_check_origin(lw);
}
void
lw->selected_start = n;
lw->selected_end = n;
}
+
+ list_window_check_selected(lw);
+ list_window_check_origin(lw);
}
void
}
void
-list_window_paint(struct list_window *lw,
+list_window_paint(const struct list_window *lw,
list_window_callback_fn_t callback,
void *callback_data)
{
bool show_cursor = !lw->hide_cursor;
bool highlight = false;
- if (show_cursor) {
- int start = lw->start;
- if ((unsigned) options.scroll_offset * 2 >= lw->rows)
- // Center if the offset is more than half the screen
- start = lw->selected - lw->rows / 2;
- else
- {
- if (lw->selected < lw->start + options.scroll_offset)
- start = lw->selected - options.scroll_offset;
-
- if (lw->selected >= lw->start + lw->rows - options.scroll_offset)
- {
- start = lw->selected - lw->rows + 1 + options.scroll_offset;
- }
- }
-
- if (start + lw->rows > lw->length)
- start = lw->length - lw->rows;
-
- if (start < 0 || lw->length == 0)
- start = 0;
-
- lw->start = start;
- }
-
show_cursor = show_cursor &&
(!options.hardware_cursor || lw->range_selection);
diff --git a/src/list_window.h b/src/list_window.h
index edb3e260bd3f13a4205a0378516b38b20df3d84e..eef6b9a7c43c1d8739971bfe3470e8041f65056a 100644 (file)
--- a/src/list_window.h
+++ b/src/list_window.h
list_window_set_length(struct list_window *lw, unsigned length);
/* paint a list window */
-void list_window_paint(struct list_window *lw,
+void list_window_paint(const struct list_window *lw,
list_window_callback_fn_t callback,
void *callback_data);