-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringlist.h
54 lines (43 loc) · 1.2 KB
/
stringlist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @file stringlist.h
* @brief Something for choosing from a list of strings, works
* a bit like LineEdit.
*
*/
#ifndef __STRINGLIST_H
#define __STRINGLIST_H
#include <string>
#include <vector>
#include "editor.h"
class StringList : public Editor {
// used to filter the list
// for only items starting with prefix.
std::string prefix;
std::vector<std::string> list; // the input list
// the input list after prefix filter applied
std::vector<std::string> listFiltered;
unsigned int cursor; // currently selected item
unsigned int pagelen;
void recalcFilter();
public:
void begin(std::string p,std::vector<std::string>& l){
Editor::begin(p);
cursor = 0;
list = l;
listFiltered = list;
prefix = "";
}
// call when a thing has noticed that we're done.
// will return data and reset state. May also return int index.
std::string consume(){
state = Idle;
if(listFiltered.size() && cursor<listFiltered.size()){
return listFiltered[cursor];
} else {
return "";
}
}
void display();
EditState handleKey(int k);
};
#endif /* __STRINGLIST_H */