summaryrefslogtreecommitdiffstats
path: root/Panel.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-01-27 23:28:37 -0200
committerHisham Muhammad <hisham@gobolinux.org>2018-02-26 20:13:09 -0300
commit1edcfad874e7ed093bd8489a42f7a6f86c19e5c5 (patch)
tree979449ec7745af2b37dce3b873434ccd8e9c2273 /Panel.c
parentd4ea7cd65ccf8551cabb0706167b2c15aad7866d (diff)
Move responsibility for cursor placement to Panels
Diffstat (limited to 'Panel.c')
-rw-r--r--Panel.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/Panel.c b/Panel.c
index 1e53b4a4..e9d69ecb 100644
--- a/Panel.c
+++ b/Panel.c
@@ -57,6 +57,7 @@ typedef struct PanelClass_ {
struct Panel_ {
Object super;
int x, y, w, h;
+ int cursorX, cursorY;
WINDOW* window;
Vector* items;
int selected;
@@ -66,6 +67,7 @@ struct Panel_ {
int scrollV;
short scrollH;
bool needsRedraw;
+ bool cursorOn;
FunctionBar* currentBar;
FunctionBar* defaultBar;
RichString header;
@@ -85,6 +87,11 @@ struct Panel_ {
#define KEY_CTRL(l) ((l)-'A'+1)
+void Panel_setCursorToSelection(Panel* this) {
+ this->cursorY = this->y + this->selected - this->scrollV + 1;
+ this->cursorX = this->x + this->selectedLen - this->scrollH;
+}
+
PanelClass Panel_class = {
.super = {
.extends = Class(Object),
@@ -112,6 +119,8 @@ void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool
this->y = y;
this->w = w;
this->h = h;
+ this->cursorX = 0;
+ this->cursorY = 0;
this->eventHandlerState = NULL;
this->items = Vector_new(type, owner, DEFAULT_SIZE);
this->scrollV = 0;
@@ -367,7 +376,6 @@ void Panel_draw(Panel* this, bool focus) {
RichString_end(old);
}
this->oldSelected = this->selected;
- move(0, 0);
}
bool Panel_onKey(Panel* this, int key) {
@@ -499,3 +507,15 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
}
return IGNORED;
}
+
+int Panel_getCh(Panel* this) {
+ if (this->cursorOn) {
+ move(this->cursorY, this->cursorX);
+ curs_set(1);
+ } else {
+ curs_set(0);
+ }
+ set_escdelay(25);
+ return getch();
+}
+

© 2014-2024 Faster IT GmbH | imprint | privacy policy