aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ui.c26
-rw-r--r--src/ui.h9
-rw-r--r--src/ui_input.c15
3 files changed, 38 insertions, 12 deletions
diff --git a/src/ui.c b/src/ui.c
index 780452d..bb12936 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -40,6 +40,7 @@
static unsigned int max_x, max_y;
+static unsigned int cur_x, cur_y;
static WINDOW *wnd_main;
static struct nask_ui /* simple linked list to all UI objects */ *nui = NULL,
/* current active input */ *active = NULL;
@@ -94,6 +95,25 @@ unregister_ui_elt(void *data)
}
}
+void
+ui_set_cur(unsigned int x, unsigned int y)
+{
+ cur_x = x;
+ cur_y = y;
+}
+
+int
+ui_get_curx(void)
+{
+ return (cur_x);
+}
+
+int
+ui_get_cury(void)
+{
+ return (cur_y);
+}
+
int
activate_ui_input(void *data)
{
@@ -146,8 +166,6 @@ static int
do_ui_update(bool timed_out)
{
int retval = UICB_OK;
- int curx = getcurx(wnd_main);
- int cury = getcury(wnd_main);
struct nask_ui *cur = nui;
/* call all draw callback's */
@@ -166,7 +184,7 @@ do_ui_update(bool timed_out)
mvprintw(0, max_x - STRLEN(APP_TIMEOUT_FMT), "[" APP_TIMEOUT_FMT "]", atmout);
attroff(COLOR_PAIR(1));
/* EoT (End of Todo) */
- wmove(wnd_main, cury, curx);
+ wmove(wnd_main, cur_y, cur_x);
wrefresh(wnd_main);
return (retval);
}
@@ -212,6 +230,8 @@ init_ui(void)
wnd_main = initscr();
max_x = getmaxx(wnd_main);
max_y = getmaxy(wnd_main);
+ cur_x = getcurx(wnd_main);
+ cur_y = getcury(wnd_main);
start_color();
init_pair(1, COLOR_RED, COLOR_WHITE);
init_pair(2, COLOR_WHITE, COLOR_BLACK);
diff --git a/src/ui.h b/src/ui.h
index fa895ca..68f9fcd 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -48,6 +48,15 @@ register_ui_elt(struct ui_callbacks *cbs, void *data, WINDOW *wnd);
void
unregister_ui_elt(void *data);
+void
+ui_set_cur(unsigned int x, unsigned int y);
+
+int
+ui_get_curx(void);
+
+int
+ui_get_cury(void);
+
int
activate_ui_input(void *data);
diff --git a/src/ui_input.c b/src/ui_input.c
index 3065f1d..b32570b 100644
--- a/src/ui_input.c
+++ b/src/ui_input.c
@@ -124,13 +124,8 @@ int
activate_input(WINDOW *win, struct input *a)
{
if (a == NULL) return (UICB_ERR_UNDEF);
- size_t p_len = strlen(a->prompt);
curs_set(1);
- if (win == NULL) {
- move(a->y, a->x + p_len + a->cur_pos);
- } else {
- wmove(win, a->y, a->x + p_len + a->cur_pos);
- }
+ ui_set_cur(a->x + strlen(a->prompt) + a->cur_pos, a->y);
return (activate_ui_input( (void *) a ));
}
@@ -150,7 +145,7 @@ add_input(WINDOW *win, struct input *a, int key)
++a->input_pos;
++a->input_len;
a->cur_pos = (a->cur_pos+1 < a->width ? a->cur_pos+1 : a->cur_pos);
- //print_input(win, a);
+ ui_set_cur(a->x + strlen(a->prompt) + a->cur_pos, a->y);
ui_thrd_force_update();
return (UICB_OK);
}
@@ -172,7 +167,8 @@ del_input(WINDOW *win, struct input *a)
--a->cur_pos;
}
mvwprintw(win, a->y, a->x + a->cur_pos + strlen(a->prompt), "_");
- print_input(win, a);
+ ui_set_cur(a->x + strlen(a->prompt) + a->cur_pos, a->y);
+ ui_thrd_force_update();
return (UICB_OK);
}
@@ -184,7 +180,8 @@ clear_input(WINDOW *win, struct input *a)
a->input_len = 0;
a->input_pos = 0;
a->cur_pos = 0;
- print_input(win, a);
+ ui_set_cur(a->x + strlen(a->prompt) + a->cur_pos, a->y);
+ ui_thrd_force_update();
return (UICB_OK);
}