aboutsummaryrefslogtreecommitdiff
path: root/src/ui/members.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/members.c')
-rw-r--r--src/ui/members.c60
1 files changed, 6 insertions, 54 deletions
diff --git a/src/ui/members.c b/src/ui/members.c
index 509e03b..b0abb7c 100644
--- a/src/ui/members.c
+++ b/src/ui/members.c
@@ -24,6 +24,7 @@
24 24
25#include "members.h" 25#include "members.h"
26 26
27#include "list_input.h"
27#include "../application.h" 28#include "../application.h"
28#include "../util.h" 29#include "../util.h"
29 30
@@ -32,16 +33,12 @@ members_event(UI_MEMBERS_Handle *members,
32 struct MESSENGER_Application *app, 33 struct MESSENGER_Application *app,
33 int key) 34 int key)
34{ 35{
35 members->line_index = 0; 36 list_input_reset(members);
36 members->selected = NULL;
37
38 int count = 0;
39 37
40 UI_MEMBERS_List *element = members->head; 38 UI_MEMBERS_List *element = members->head;
41 while (element) 39 while (element)
42 { 40 {
43 count++; 41 list_input_select(members, 1, element->contact);
44
45 element = element->next; 42 element = element->next;
46 } 43 }
47 44
@@ -50,72 +47,28 @@ members_event(UI_MEMBERS_Handle *members,
50 case 27: 47 case 27:
51 case KEY_EXIT: 48 case KEY_EXIT:
52 case '\t': 49 case '\t':
53 {
54 app->chat.show_members = FALSE; 50 app->chat.show_members = FALSE;
55 break; 51 break;
56 }
57 case KEY_UP:
58 {
59 members->line_selected--;
60 break;
61 }
62 case KEY_DOWN:
63 {
64 members->line_selected++;
65 break;
66 }
67 case '\n': 52 case '\n':
68 case KEY_ENTER: 53 case KEY_ENTER:
69 {
70 if (members->selected) 54 if (members->selected)
71 { 55 {
72 // TODO 56 // TODO
73 } 57 }
74 58
75 break; 59 break;
76 }
77 default: 60 default:
78 break; 61 break;
79 } 62 }
80 63
81 if (members->line_selected < 0) 64 list_input_event(members, key);
82 members->line_selected = 0;
83 else if (members->line_selected >= count)
84 members->line_selected = count - 1;
85
86 if (!(members->window))
87 return;
88
89 const int height = getmaxy(members->window);
90 const int y = members->line_selected - members->line_offset;
91
92 if (y < 0)
93 members->line_offset += y;
94 else if (y + 1 >= height)
95 members->line_offset += y + 1 - height;
96
97 if (members->line_offset < 0)
98 members->line_offset = 0;
99 else if (members->line_offset >= count)
100 members->line_offset = count - 1;
101} 65}
102 66
103static void 67static void
104_members_iterate_print(UI_MEMBERS_Handle *members, 68_members_iterate_print(UI_MEMBERS_Handle *members,
105 const struct GNUNET_CHAT_Contact *contact) 69 const struct GNUNET_CHAT_Contact *contact)
106{ 70{
107 const bool selected = (members->line_selected == members->line_index); 71 list_input_print(members, 1);
108 const int y = members->line_index - members->line_offset;
109
110 members->line_index++;
111
112 if (y < 0)
113 return;
114
115 const int height = getmaxy(members->window);
116
117 if (y >= height)
118 return;
119 72
120 const int attrs_select = A_BOLD; 73 const int attrs_select = A_BOLD;
121 74
@@ -142,14 +95,13 @@ members_print(UI_MEMBERS_Handle *members)
142 if (!(members->window)) 95 if (!(members->window))
143 return; 96 return;
144 97
145 members->line_index = 0; 98 list_input_reset(members);
146 werase(members->window); 99 werase(members->window);
147 100
148 UI_MEMBERS_List *element = members->head; 101 UI_MEMBERS_List *element = members->head;
149 while (element) 102 while (element)
150 { 103 {
151 _members_iterate_print(members, element->contact); 104 _members_iterate_print(members, element->contact);
152
153 element = element->next; 105 element = element->next;
154 } 106 }
155} 107}