From dc74baecf7ffcd0cb89fddea078b464bed2f1ddf Mon Sep 17 00:00:00 2001 From: Alexander Zhylin Date: Fri, 12 Dec 2025 12:21:44 +0200 Subject: [PATCH] ui: cursor fix --- TODO.md | 3 ++- src/ui/widget/dialogue.c | 26 ++++++++++++++++++++++++++ src/ui/widget/group.c | 18 +----------------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/TODO.md b/TODO.md index 48eb438..010957e 100644 --- a/TODO.md +++ b/TODO.md @@ -6,4 +6,5 @@ TODO: - [ ] Hotkeys for buttons - [ ] Simpler refresh on typing / entering in input - [ ] Group elements as lists -- [ ] Process arrows \ No newline at end of file +- [ ] Process arrows +- [ ] active_id -> просто указатель на элемент diff --git a/src/ui/widget/dialogue.c b/src/ui/widget/dialogue.c index 5dc7ee9..b9d9c21 100644 --- a/src/ui/widget/dialogue.c +++ b/src/ui/widget/dialogue.c @@ -6,6 +6,7 @@ #include "../app.h" #include "dialogue.h" #include "group.h" +#include "input.h" #define INCR_ACTIVE_ID(d, current, next) \ if (d->active.id != d->current->last_id) { \ @@ -119,6 +120,8 @@ void dialogue_init_active_id(dialogue_t *dialogue) { int32_t draw_dialogue(dialogue_t *d) { if (!d->is_initiated) return -1; + group_el_t *ae_ptr = NULL; /* active element */ + uint32_t ae_idx; /* active element */ /* count dimensions */ uint32_t x = 1; /* when uses box */ uint32_t y = 1; /* when uses box */ @@ -176,6 +179,29 @@ int32_t draw_dialogue(dialogue_t *d) { if (d->g_action != NULL) { draw_group(d->win, d->g_action, d->active.id, &(d->w)); } + + /* move cursor */ + FIND_ACTIVE_ELEMENT(d->g_content, d->active.id, ae_ptr, ae_idx); + if (ae_ptr == NULL) FIND_ACTIVE_ELEMENT(d->g_action, d->active.id, ae_ptr, ae_idx); + + if (ae_ptr != NULL && ae_ptr->id == d->active.id) { + if (ae_ptr->type == w_input) { + input_t *input = ae_ptr->element; + d->w.cur.y = input->w.cur.y; + if (input->max_len == input->value_len) { + d->w.cur.x = input->w.cur.x + input->value_len - 1; + } else { + d->w.cur.x = input->w.cur.x + input->value_len; + } + if (d->w.cur.y || d->w.cur.x) { + wmove(d->win, d->w.cur.y, d->w.cur.x); + curs_set(1); + } + } else { + curs_set(0); + } + } + return 0; }; diff --git a/src/ui/widget/group.c b/src/ui/widget/group.c index e165cfa..d13abef 100644 --- a/src/ui/widget/group.c +++ b/src/ui/widget/group.c @@ -1,6 +1,7 @@ #include "group.h" #include "button.h" #include "input.h" +#include #include #include #include @@ -125,23 +126,6 @@ void draw_group(WINDOW *win, group_t *group, int32_t active_id, break; } } - /* move cursor */ - FIND_ACTIVE_ELEMENT(group, active_id, active_element, active_idx); - - if (active_element != NULL && active_element->id == active_id && - active_element->type == w_input) { - input_t *input = active_element->element; - dialog_w->cur.y = input->w.cur.y; - if (input->max_len == input->value_len) { - dialog_w->cur.x = input->w.cur.x + input->value_len - 1; - } else { - dialog_w->cur.x = input->w.cur.x + input->value_len; - } - } - if (dialog_w->cur.y || dialog_w->cur.x) { - wmove(win, dialog_w->cur.y, dialog_w->cur.x); - curs_set(1); - } } void destroy_group(group_t *group) {