aboutsummaryrefslogtreecommitdiff
path: root/ui_input.c
diff options
context:
space:
mode:
authortoni <matzeton@googlemail.com>2014-12-07 03:11:36 +0100
committertoni <matzeton@googlemail.com>2014-12-07 03:20:19 +0100
commite3ec8f9259d132eec7071343931fd26733d1dd64 (patch)
treeb352ea117095f0e51117f7c14919b8bd24b66c2a /ui_input.c
parentd9eec1d5a32976cc95cce59a5a4532fb5adea5b9 (diff)
- preparing majore update (ui_input) ..
Diffstat (limited to 'ui_input.c')
-rw-r--r--ui_input.c64
1 files changed, 51 insertions, 13 deletions
diff --git a/ui_input.c b/ui_input.c
index 44ce318..af88b3a 100644
--- a/ui_input.c
+++ b/ui_input.c
@@ -1,19 +1,24 @@
#include <stdlib.h>
+#include <string.h>
#include "ui.h"
#include "ui_input.h"
struct input *
-init_input(bool box, bool shadow, char *prompt, size_t input_len)
+init_input(unsigned int x, unsigned int y, unsigned int width, char *prompt, size_t input_len)
{
struct input *a = calloc(1, sizeof(struct input));
- a->box = box;
- a->shadow = shadow;
+ a->x = x;
+ a->y = y;
+ a->width = width;
a->input = calloc(input_len+1, sizeof(char));
- a->input_len = input_len;
- a->prompt = prompt;
+ a->input_max = input_len;
+ a->input_len = 0;
+ a->input_pos = 0;
+ a->prompt = strdup(prompt);
+ a->active = false;
return (a);
}
@@ -23,26 +28,59 @@ free_input(struct input *a)
if (a->input != NULL) {
free(a->input);
}
+ free(a->prompt);
free(a);
}
+static void
+print_input(WINDOW *win, struct input *a)
+{
+ char *tmp;
+ int i;
+ size_t p_len = strlen(a->prompt);
+
+ if (win == NULL) {
+ mvprintw(a->y, a->x, a->prompt);
+ tmp = calloc(a->width+1, sizeof(char));
+ for (i = 0; i < a->width; i++) {
+ *(tmp + i) = '_';
+ }
+ mvprintw(a->y, a->x + p_len, tmp);
+ free(tmp);
+ mvprintw(a->y, a->x + p_len, a->input);
+ }
+}
+
+int
+post_input_cb(WINDOW *win, void *data, bool needs_update)
+{
+ struct input *a = (struct input *) data;
+
+ if (a == NULL) return (UICB_ERR_UNDEF);
+ if (a->active == true) {
+ if (win == NULL) {
+ move(a->y, a->x + a->input_pos);
+ } else {
+ wmove(win, a->y, a->x + a->input_pos);
+ }
+ return (UICB_CURSOR);
+ }
+ return (UICB_OK);
+}
+
+
int
input_cb(WINDOW *win, void *data, bool needs_update)
{
struct input *a = (struct input *) data;
if (a == NULL) return (UICB_ERR_UNDEF);
-mvaddch(7,1,'A');
-wrefresh(win);
-refresh();
+ print_input(win, a);
return (UICB_OK);
}
void
-register_input(unsigned int x, unsigned int y, unsigned int width, unsigned int height, struct input *a, chtype attr)
+register_input(WINDOW *win, struct input *a, chtype attr)
{
- WINDOW *wnd = newwin(height, width, y, x);
- box(wnd, 0, 0);
-wrefresh(wnd);
- register_ui_elt(input_cb, (void *) a, wnd, attr);
+ register_ui_elt(input_cb, post_input_cb, (void *) a, win, attr);
}