summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2013-05-19 01:02:19 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2013-05-19 01:07:08 +0200
commit110f2523d37658081761c08714fffc421144e6f4 (patch)
tree9f6d28eba2878f8cbde39c2f6c44f0217d4505cb /src
parentcaac68a3ed74501f97c5d67bd5e6280542c87cfe (diff)
downloadtdv-110f2523d37658081761c08714fffc421144e6f4.tar.gz
tdv-110f2523d37658081761c08714fffc421144e6f4.tar.xz
tdv-110f2523d37658081761c08714fffc421144e6f4.zip
Fix window resizing
Diffstat (limited to 'src')
-rw-r--r--src/sdtui.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/sdtui.c b/src/sdtui.c
index cf1c315..9ac7e71 100644
--- a/src/sdtui.c
+++ b/src/sdtui.c
@@ -272,8 +272,7 @@ app_reload_view (Application *self)
if (self->entries->len != 0)
g_ptr_array_remove_range (self->entries, 0, self->entries->len);
- self->selected = 0;
- gint remains = LINES - 1;
+ gint remains = LINES - 1 + self->top_offset;
StardictIterator *iterator =
stardict_iterator_new (self->dict, self->top_position);
while (remains > 0 && stardict_iterator_is_valid (iterator))
@@ -533,7 +532,7 @@ append_entry (Application *self, guint32 position)
/** Counts the number of definitions available for seeing. */
static guint
-count_view_items (Application *self)
+app_count_view_items (Application *self)
{
guint i, n_definitions = 0;
for (i = 0; i < self->entries->len; i++)
@@ -549,7 +548,7 @@ static gboolean
app_scroll_up (Application *self, guint n)
{
gboolean success = TRUE;
- guint n_definitions = count_view_items (self);
+ guint n_definitions = app_count_view_items (self);
while (n--)
{
if (self->top_offset > 0)
@@ -590,7 +589,7 @@ static gboolean
app_scroll_down (Application *self, guint n)
{
gboolean success = TRUE;
- guint n_definitions = count_view_items (self);
+ guint n_definitions = app_count_view_items (self);
while (n--)
{
if (self->entries->len == 0)
@@ -712,6 +711,7 @@ app_search_for_entry (Application *self)
self->top_position = stardict_iterator_get_offset (iterator);
self->top_offset = 0;
+ self->selected = 0;
g_object_unref (iterator);
app_reload_view (self);
@@ -764,11 +764,22 @@ app_process_nonchar_code (Application *self, CursesEvent *event)
switch (event->code)
{
case KEY_RESIZE:
- // TODO adapt to the new window size, COLS, LINES
- // mind the position of the selection cursor
+ {
app_reload_view (self);
+
+ guint n_visible = app_count_view_items (self) - self->top_offset;
+ if ((gint) n_visible > LINES - 1)
+ n_visible = LINES - 1;
+
+ if (self->selected >= n_visible)
+ {
+ app_scroll_down (self, self->selected - n_visible + 1);
+ self->selected = n_visible - 1;
+ }
+
app_redraw (self);
break;
+ }
case KEY_MOUSE:
if (!(event->mouse.bstate & BUTTON1_PRESSED))
break;
@@ -785,7 +796,7 @@ app_process_nonchar_code (Application *self, CursesEvent *event)
}
}
else if (event->mouse.y <= (int)
- (count_view_items (self) - self->top_offset))
+ (app_count_view_items (self) - self->top_offset))
{
self->selected = event->mouse.y - 1;
app_redraw_view (self);
@@ -805,7 +816,7 @@ app_process_nonchar_code (Application *self, CursesEvent *event)
break;
case KEY_DOWN:
if ((gint) self->selected < LINES - 2 &&
- self->selected < count_view_items (self) - self->top_offset - 1)
+ self->selected < app_count_view_items (self) - self->top_offset - 1)
{
self->selected++;
app_redraw_view (self);