summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTillmann Karras <tilkax@gmail.com>2013-11-26 00:45:23 +0100
committerTillmann Karras <tilkax@gmail.com>2013-11-26 16:32:55 +0100
commitc0b206c5e5860d223678a21644ea2d3a1eb07880 (patch)
tree98849bf1d509c67f045b92f2c0c13636a51de4e9
parent3cf6365282a471bd2e6a4be23033fc0d61a99f7d (diff)
Move cursor to ui_textinput-specified position
-rw-r--r--src/ui_util.c26
-rw-r--r--src/uit_conn.c4
-rw-r--r--src/uit_dl.c4
-rw-r--r--src/uit_fl.c4
-rw-r--r--src/uit_hub.c2
-rw-r--r--src/uit_main.c2
-rw-r--r--src/uit_msg.c2
-rw-r--r--src/uit_search.c4
-rw-r--r--src/uit_userlist.c4
9 files changed, 32 insertions, 20 deletions
diff --git a/src/ui_util.c b/src/ui_util.c
index 3cccd8a..d0646b1 100644
--- a/src/ui_util.c
+++ b/src/ui_util.c
@@ -75,6 +75,11 @@ struct ui_attr_t {
int attr;
}
+struct ui_cursor_t {
+ int x;
+ int y;
+}
+
#define UIC(n) (ui_colors[(ui_coltype)UIC_##n].a)
#endif // INTERFACE
@@ -834,7 +839,7 @@ char *ui_textinput_reset(ui_textinput_t *ti) {
// must be drawn last, to keep the cursor position correct
// also not the most efficient function ever, but probably fast enough.
-void ui_textinput_draw(ui_textinput_t *ti, int y, int x, int col) {
+void ui_textinput_draw(ui_textinput_t *ti, int y, int x, int col, struct ui_cursor_t *cur) {
// | |
// "Some random string etc etc"
// f # l
@@ -877,8 +882,13 @@ void ui_textinput_draw(ui_textinput_t *ti, int y, int x, int col) {
}
i++;
}
- move(y, x+pos);
+ x += pos;
+ move(y, x);
curs_set(1);
+ if (cur) {
+ cur->x = x;
+ cur->y = y;
+ }
}
@@ -1264,26 +1274,28 @@ static void ui_listing_fixtop(ui_listing_t *ul, int height) {
// TODO: The return value is only correct if no skip function is used or if
// there are otherwise no hidden rows. It'll give a blatantly wrong number if
// there are.
-int ui_listing_draw(ui_listing_t *ul, int top, int bottom, int *cur, void (*cb)(ui_listing_t *, GSequenceIter *, int, void *)) {
+int ui_listing_draw(ui_listing_t *ul, int top, int bottom, struct ui_cursor_t *cur, void (*cb)(ui_listing_t *, GSequenceIter *, int, void *)) {
int query_height = !!ul->query;
int listing_height = 1 + bottom - top - query_height;
ui_listing_fixtop(ul, listing_height);
- if(cur)
- *cur = top;
+ if(cur) {
+ cur->x = 0;
+ cur->y = top;
+ }
// draw
GSequenceIter *n = ul->top;
while(top <= bottom - query_height && !g_sequence_iter_is_end(n)) {
if(cur && n == ul->sel)
- *cur = top;
+ cur->y = top;
cb(ul, n, top, ul->dat);
n = ui_listing_next(ul, n);
top++;
}
if (ul->query) {
mvaddstr(bottom, 0, "search>");
- ui_textinput_draw(ul->query, bottom, 8, wincols-8);
+ ui_textinput_draw(ul->query, bottom, 8, wincols-8, cur);
}
ui_listing_updateisbegin(ul);
diff --git a/src/uit_conn.c b/src/uit_conn.c
index f58a61c..6392ccf 100644
--- a/src/uit_conn.c
+++ b/src/uit_conn.c
@@ -246,7 +246,7 @@ static void t_draw(ui_tab_t *tab) {
attroff(UIC(list_header));
int bottom = t->details ? winrows-11 : winrows-3;
- int cursor;
+ struct ui_cursor_t cursor;
ui_listing_draw(t->list, 2, bottom-1, &cursor, t_draw_row);
// footer
@@ -273,7 +273,7 @@ static void t_draw(ui_tab_t *tab) {
// detailed info
if(t->details)
t_draw_details(t, bottom);
- move(cursor, 0);
+ move(cursor.y, cursor.x);
}
diff --git a/src/uit_dl.c b/src/uit_dl.c
index ecaf4c0..25a52e2 100644
--- a/src/uit_dl.c
+++ b/src/uit_dl.c
@@ -213,7 +213,7 @@ static void t_draw(ui_tab_t *tab) {
attroff(UIC(list_header));
int bottom = dltab->details ? winrows-14 : winrows-4;
- int cursor;
+ struct ui_cursor_t cursor;
int pos = ui_listing_draw(dltab->list, 2, bottom-1, &cursor, draw_row);
dl_t *sel = g_sequence_iter_is_end(dltab->list->sel) ? NULL : g_sequence_get(dltab->list->sel);
@@ -247,7 +247,7 @@ static void t_draw(ui_tab_t *tab) {
else
ui_listing_draw(dltab->users, bottom+2, winrows-3, &cursor, dud_draw_row);
}
- move(cursor, 0);
+ move(cursor.y, cursor.x);
}
diff --git a/src/uit_fl.c b/src/uit_fl.c
index 3bf2024..9989d4b 100644
--- a/src/uit_fl.c
+++ b/src/uit_fl.c
@@ -360,7 +360,7 @@ static void t_draw(ui_tab_t *tab) {
// rows
int pos = -1;
- int cursor = 2;
+ struct ui_cursor_t cursor = { 0, 2 };
if(t->loading)
mvaddstr(3, 2, "Loading filelist...");
else if(t->err)
@@ -394,7 +394,7 @@ static void t_draw(ui_tab_t *tab) {
mvprintw(winrows-3, 0, " %d items, %s bytes", num, str_fullsize(sel->size));
}
attroff(UIC(separator));
- move(cursor, 0);
+ move(cursor.y, cursor.x);
}
diff --git a/src/uit_hub.c b/src/uit_hub.c
index 781f1a9..12ddd6b 100644
--- a/src/uit_hub.c
+++ b/src/uit_hub.c
@@ -141,7 +141,7 @@ static void t_draw(ui_tab_t *tab) {
mvaddstr(winrows-3, 0, tab->name);
addstr("> ");
int pos = str_columns(tab->name)+2;
- ui_textinput_draw(ui_global_textinput, winrows-3, pos, wincols-pos);
+ ui_textinput_draw(ui_global_textinput, winrows-3, pos, wincols-pos, NULL);
}
diff --git a/src/uit_main.c b/src/uit_main.c
index 10bab08..c32b024 100644
--- a/src/uit_main.c
+++ b/src/uit_main.c
@@ -61,7 +61,7 @@ static void t_draw(ui_tab_t *t) {
ui_logwindow_draw(t->log, 1, 0, winrows-4, wincols);
mvaddstr(winrows-3, 0, "main>");
- ui_textinput_draw(ui_global_textinput, winrows-3, 6, wincols-6);
+ ui_textinput_draw(ui_global_textinput, winrows-3, 6, wincols-6, NULL);
}
diff --git a/src/uit_msg.c b/src/uit_msg.c
index f3f737d..a318f4e 100644
--- a/src/uit_msg.c
+++ b/src/uit_msg.c
@@ -83,7 +83,7 @@ static void t_draw(ui_tab_t *tab) {
mvaddstr(winrows-3, 0, tab->name);
addstr("> ");
int pos = str_columns(tab->name)+2;
- ui_textinput_draw(ui_global_textinput, winrows-3, pos, wincols-pos);
+ ui_textinput_draw(ui_global_textinput, winrows-3, pos, wincols-pos, NULL);
}
diff --git a/src/uit_search.c b/src/uit_search.c
index 42a3245..338bb9f 100644
--- a/src/uit_search.c
+++ b/src/uit_search.c
@@ -241,7 +241,7 @@ static void t_draw(ui_tab_t *tab) {
attroff(UIC(list_header));
int bottom = winrows-4;
- int cursor;
+ struct ui_cursor_t cursor;
int pos = ui_listing_draw(t->list, 2, bottom-1, &cursor, draw_row);
search_r_t *sel = g_sequence_iter_is_end(t->list->sel) ? NULL : g_sequence_get(t->list->sel);
@@ -264,7 +264,7 @@ static void t_draw(ui_tab_t *tab) {
attroff(UIC(separator));
if(sel)
mvaddnstr(bottom+1, 3, sel->file, str_offset_from_columns(sel->file, wincols-3));
- move(cursor, 0);
+ move(cursor.y, cursor.x);
}
diff --git a/src/uit_userlist.c b/src/uit_userlist.c
index 652a4fc..87fba8e 100644
--- a/src/uit_userlist.c
+++ b/src/uit_userlist.c
@@ -257,7 +257,7 @@ static void t_draw(ui_tab_t *tab) {
// rows
int bottom = t->details ? winrows-7 : winrows-3;
- int cursor;
+ struct ui_cursor_t cursor;
int pos = ui_listing_draw(t->list, 2, bottom-1, &cursor, draw_row);
// footer
@@ -301,7 +301,7 @@ static void t_draw(ui_tab_t *tab) {
// TODO: CID?
}
- move(cursor, 0);
+ move(cursor.y, cursor.x);
}
#undef DRAW_COL