Chesto 0.9
A declarative and element-based library for creating GUIs on homebrew'd consoles
DropDown.hpp
1#include "Button.hpp"
2#include <vector>
3#include <utility>
4#include <functional>
5#include <string>
6#include "Container.hpp"
7#include "Screen.hpp"
8#include "ListElement.hpp"
9
10#ifndef DROPDOWN_HPP_
11#define DROPDOWN_HPP_
12
13namespace Chesto {
14
15class DropDownChoices;
16
18{
19public:
20 void rebuildUI() override {}
21};
22
23class DropDown : public Button
24{
25public:
27 int physicalButton,
28 std::vector<std::pair<std::string, std::string>> choices,
29 std::function<void(std::string)> onSelect,
30 int textSize,
31 std::string defaultChoice = "",
32 bool isDarkMode = false
33 );
34 std::vector<std::pair<std::string, std::string>> choices;
35 std::function<void(std::string)> onSelect;
36 std::string selectedChoice; // Current selection
37
38 // element overriden functions
39 bool process(InputEvents* event);
40};
41
42// DropDownChoices is now a Screen that gets pushed onto the screen stack
43class DropDownChoices : public Screen
44{
45public:
47 std::vector<std::pair<std::string, std::string>> choices,
48 std::function<void(std::string)> onSelect,
49 bool isDarkMode,
50 std::string header = ""
51 );
52 bool process(InputEvents* event) override;
53 void render(Element* parent) override;
54 void rebuildUI() override; // Required by Screen
55
56 int curHighlighted = -1;
57 Container* container = nullptr; // the container that contains the actual choice elements (used for navigation)
58 ListElement* scrollList = nullptr; // the scrollable wrapper for everything
59
60private:
61 std::vector<std::pair<std::string, std::string>> choices;
62 std::function<void(std::string)> onSelectCallback;
63 bool isDarkMode;
64 std::string header;
65};
66
67} // namespace Chesto
68
69#endif
void rebuildUI() override
Definition: DropDown.cpp:94
bool process(InputEvents *event) override
process any input that is received for this element
Definition: DropDown.cpp:156
void render(Element *parent) override
display the current state of the display
Definition: DropDown.cpp:152
bool process(InputEvents *event)
process any input that is received for this element
Definition: DropDown.cpp:40
Element * parent
the parent element (reference only, not owned)
Definition: Element.hpp:116