1 #include <Interface/Menu/MenuItemTextlist.hpp> 2 #include <Misc/Utils.hpp> 3 #include <Config/Globals.hpp> 4 #include <Flow/InputManager.hpp> 8 MenuItemTextlist::MenuItemTextlist(std::string label,
int id, std::vector<std::string> options, std::string initial):
13 this->
type = MenuItem::TEXTLIST;
15 for (
unsigned int i = 0; i < options.size(); ++i)
17 if (options[i] == initial)
19 this->currentIndex = i;
23 if ((this->currentIndex == -1) || (options.empty()))
24 throw std::runtime_error(
"Invalid initial value for MenuItemTextlist");
28 std::string text = this->options[this->currentIndex];
38 (width - text.size() - 5),
41 int rightmost = x + width;
43 window->
print(((hilite)?
46 rightmost - text.size() - 2,
49 Globals::Theme::hilite_text:
50 Globals::Theme::text));
52 window->
print(((hilite)?
58 Globals::Theme::hilite_text:
59 Globals::Theme::text));
62 rightmost - text.size() - 1,
64 Globals::Theme::hilite_text);
68 if (InputManager::noKeyPressed())
71 if (InputManager::isPressed(
"left") ||
72 InputManager::isPressed(KEY_LEFT))
75 else if (InputManager::isPressed(
"right") ||
76 InputManager::isPressed(KEY_RIGHT))
79 else if (InputManager::isPressed(
'r') ||
80 InputManager::isPressed(
'R') ||
81 InputManager::isPressed(
' '))
84 void MenuItemTextlist::increase()
88 if (this->currentIndex >= (
int)this->options.size())
89 this->currentIndex = 0;
92 void MenuItemTextlist::decrease()
96 if (this->currentIndex < 0)
97 this->currentIndex = (this->options.size() - 1);
99 void MenuItemTextlist::reset()
101 this->currentIndex = 0;
103 std::string MenuItemTextlist::currentText()
105 return this->options[this->currentIndex];
A segment of the terminal screen (2D char matrix).
void print(std::string str, int x, int y, ColorPair pair=0)
Shows text #str at #x #y on the window with color #pair.