aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/MenuSearch.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/MenuSearch.hh')
-rw-r--r--src/FbTk/MenuSearch.hh60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/FbTk/MenuSearch.hh b/src/FbTk/MenuSearch.hh
new file mode 100644
index 0000000..d642929
--- /dev/null
+++ b/src/FbTk/MenuSearch.hh
@@ -0,0 +1,60 @@
1#ifndef _MENU_SEARCH_HH_
2#define _MENU_SEARCH_HH_
3
4#include <vector>
5#include <string>
6#include <cstddef>
7
8namespace FbTk {
9
10class MenuItem;
11
12
13// a small helper which applies search operations on a list of MenuItems*.
14// the former incarnation of this class was FbTk::TypeAhead in combination with
15// the now non-existent FbTk::SearchResults, but the complexity of these
16// are not needed for our use case. as a bonus we have less lose parts
17// flying around.
18
19class MenuSearch {
20public:
21
22 enum Mode {
23 NOWHERE,
24 ITEMSTART,
25 SOMEWHERE,
26
27 DEFAULT = ITEMSTART
28 };
29
30 static void setMode(Mode m);
31
32
33 MenuSearch(const std::vector<FbTk::MenuItem*>& items);
34
35 size_t size() const;
36 void clear();
37 void add(char c);
38 void backspace();
39
40 // is 'pattern' matching something?
41 bool has_match();
42
43 // would 'the_pattern' match something?
44 bool would_match(const std::string& the_pattern);
45
46 size_t num_matches();
47
48 // returns true if m_text matches against m_items[i] and stores
49 // the position where it matches in the string
50 bool get_match(size_t i, size_t& idx);
51
52 std::string pattern;
53private:
54 const std::vector<FbTk::MenuItem*>& m_items;
55};
56
57}
58
59
60#endif