-
Notifications
You must be signed in to change notification settings - Fork 1
/
ItemsList.h
60 lines (45 loc) · 1.44 KB
/
ItemsList.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
55
56
57
58
59
60
#pragma once
#include "ScreenItemIfc.h"
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <U8g2lib.h>
namespace ui {
class ItemsList : public ScreenItem {
static constexpr const std::size_t MAX_ELEMENTS = 5;
static constexpr const uint8_t LINE_HEIGHT = 10;
static constexpr const uint8_t TEXT_PADDING = 2;
static constexpr const uint8_t BORDER_WIDTH = 1;
public:
using Text = std::vector<std::string>;
using Handler = std::function<void()>;
using Items = std::vector<std::pair<const char*, Handler>>;
ItemsList(U8G2& u8g2, const char* title, Text text, Items items, Handler exitHandler)
: u8g2_(u8g2), title_(title), text_(std::move(text)), items_(std::move(items)), exitHandler_(std::move(exitHandler)) {}
ItemsList(U8G2& u8g2, const char* title, Text text, Items items)
: u8g2_(u8g2), title_(title), text_(std::move(text)), items_(std::move(items)) {}
void draw() override;
void down() override;
void up() override;
void enter() override {
items_[focused_].second();
}
void exit() override {
if (exitHandler_) {
exitHandler_();
}
}
U8G2& u8g2_;
const char* title_;
Text text_;
Items items_;
Handler exitHandler_;
std::size_t viewOffset_ = 0;
std::size_t focused_ = 0;
std::size_t maxElements_ = MAX_ELEMENTS;
uint8_t lineHeight_ = LINE_HEIGHT;
uint8_t textPadding_ = TEXT_PADDING;
uint8_t borderWidth_ = BORDER_WIDTH;
};
}