FTXUI  5.0.0
C++ functional terminal UI.
menu.cpp
Go to the documentation of this file.
1 // Copyright 2020 Arthur Sonzogni. All rights reserved.
2 // Use of this source code is governed by the MIT license that can be found in
3 // the LICENSE file.
4 #include <algorithm> // for max, fill_n, reverse
5 #include <chrono> // for milliseconds
6 #include <ftxui/dom/direction.hpp> // for Direction, Direction::Down, Direction::Left, Direction::Right, Direction::Up
7 #include <functional> // for function
8 #include <memory> // for allocator_traits<>::value_type, swap
9 #include <string> // for operator+, string
10 #include <utility> // for move
11 #include <vector> // for vector, __alloc_traits<>::value_type
12 
13 #include "ftxui/component/animation.hpp" // for Animator, Linear
14 #include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
15 #include "ftxui/component/component.hpp" // for Make, Menu, MenuEntry, Toggle
16 #include "ftxui/component/component_base.hpp" // for ComponentBase
17 #include "ftxui/component/component_options.hpp" // for MenuOption, MenuEntryOption, UnderlineOption, AnimatedColorOption, AnimatedColorsOption, EntryState
18 #include "ftxui/component/event.hpp" // for Event, Event::ArrowDown, Event::ArrowLeft, Event::ArrowRight, Event::ArrowUp, Event::End, Event::Home, Event::PageDown, Event::PageUp, Event::Return, Event::Tab, Event::TabReverse
19 #include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Released, Mouse::WheelDown, Mouse::WheelUp, Mouse::None
20 #include "ftxui/component/screen_interactive.hpp" // for Component
21 #include "ftxui/dom/elements.hpp" // for operator|, Element, reflect, Decorator, nothing, Elements, bgcolor, color, hbox, separatorHSelector, separatorVSelector, vbox, xflex, yflex, text, bold, focus, inverted, select
22 #include "ftxui/screen/box.hpp" // for Box
23 #include "ftxui/screen/color.hpp" // for Color
24 #include "ftxui/screen/util.hpp" // for clamp
25 #include "ftxui/util/ref.hpp" // for Ref, ConstStringListRef, ConstStringRef
26 
27 namespace ftxui {
28 
29 namespace {
30 
31 Element DefaultOptionTransform(const EntryState& state) {
32  std::string label = (state.active ? "> " : " ") + state.label; // NOLINT
33  Element e = text(std::move(label));
34  if (state.focused) {
35  e = e | inverted;
36  }
37  if (state.active) {
38  e = e | bold;
39  }
40  return e;
41 }
42 
43 bool IsInverted(Direction direction) {
44  switch (direction) {
45  case Direction::Up:
46  case Direction::Left:
47  return true;
48  case Direction::Down:
49  case Direction::Right:
50  return false;
51  }
52  return false; // NOT_REACHED()
53 }
54 
55 bool IsHorizontal(Direction direction) {
56  switch (direction) {
57  case Direction::Left:
58  case Direction::Right:
59  return true;
60  case Direction::Down:
61  case Direction::Up:
62  return false;
63  }
64  return false; // NOT_REACHED()
65 }
66 
67 } // namespace
68 
69 /// @brief A list of items. The user can navigate through them.
70 /// @ingroup component
71 class MenuBase : public ComponentBase, public MenuOption {
72  public:
73  explicit MenuBase(MenuOption option) : MenuOption(std::move(option)) {}
74 
75  bool IsHorizontal() { return ftxui::IsHorizontal(direction); }
76  void OnChange() {
77  if (on_change) {
78  on_change();
79  }
80  }
81 
82  void OnEnter() {
83  if (on_enter) {
84  on_enter();
85  }
86  }
87 
88  void Clamp() {
89  if (selected() != selected_previous_) {
90  SelectedTakeFocus();
91  }
92  boxes_.resize(size());
93  selected() = util::clamp(selected(), 0, size() - 1);
94  selected_previous_ = util::clamp(selected_previous_, 0, size() - 1);
95  selected_focus_ = util::clamp(selected_focus_, 0, size() - 1);
97  }
98 
99  void OnAnimation(animation::Params& params) override {
100  animator_first_.OnAnimation(params);
101  animator_second_.OnAnimation(params);
102  for (auto& animator : animator_background_) {
103  animator.OnAnimation(params);
104  }
105  for (auto& animator : animator_foreground_) {
106  animator.OnAnimation(params);
107  }
108  }
109 
110  Element Render() override {
111  Clamp();
112  UpdateAnimationTarget();
113 
114  Elements elements;
115  const bool is_menu_focused = Focused();
116  if (elements_prefix) {
117  elements.push_back(elements_prefix());
118  }
119  elements.reserve(size());
120  for (int i = 0; i < size(); ++i) {
121  if (i != 0 && elements_infix) {
122  elements.push_back(elements_infix());
123  }
124  const bool is_focused = (focused_entry() == i) && is_menu_focused;
125  const bool is_selected = (selected() == i);
126 
127  const EntryState state = {
128  entries[i],
129  false,
130  is_selected,
131  is_focused,
132  };
133 
134  auto focus_management =
135  is_menu_focused && (selected_focus_ == i) ? focus : nothing;
136 
137  const Element element =
139  : DefaultOptionTransform) //
140  (state);
141  elements.push_back(element | AnimatedColorStyle(i) | reflect(boxes_[i]) |
142  focus_management);
143  }
144  if (elements_postfix) {
145  elements.push_back(elements_postfix());
146  }
147 
148  if (IsInverted(direction)) {
149  std::reverse(elements.begin(), elements.end());
150  }
151 
152  const Element bar =
153  IsHorizontal() ? hbox(std::move(elements)) : vbox(std::move(elements));
154 
155  if (!underline.enabled) {
156  return bar | reflect(box_);
157  }
158 
159  if (IsHorizontal()) {
160  return vbox({
161  bar | xflex,
162  separatorHSelector(first_, second_, //
165  }) |
166  reflect(box_);
167  } else {
168  return hbox({
169  separatorVSelector(first_, second_, //
172  bar | yflex,
173  }) |
174  reflect(box_);
175  }
176  }
177 
178  void SelectedTakeFocus() {
179  selected_previous_ = selected();
180  selected_focus_ = selected();
181  }
182 
183  void OnUp() {
184  switch (direction) {
185  case Direction::Up:
186  selected()++;
187  break;
188  case Direction::Down:
189  selected()--;
190  break;
191  case Direction::Left:
192  case Direction::Right:
193  break;
194  }
195  }
196 
197  void OnDown() {
198  switch (direction) {
199  case Direction::Up:
200  selected()--;
201  break;
202  case Direction::Down:
203  selected()++;
204  break;
205  case Direction::Left:
206  case Direction::Right:
207  break;
208  }
209  }
210 
211  void OnLeft() {
212  switch (direction) {
213  case Direction::Left:
214  selected()++;
215  break;
216  case Direction::Right:
217  selected()--;
218  break;
219  case Direction::Down:
220  case Direction::Up:
221  break;
222  }
223  }
224 
225  void OnRight() {
226  switch (direction) {
227  case Direction::Left:
228  selected()--;
229  break;
230  case Direction::Right:
231  selected()++;
232  break;
233  case Direction::Down:
234  case Direction::Up:
235  break;
236  }
237  }
238 
239  // NOLINTNEXTLINE(readability-function-cognitive-complexity)
240  bool OnEvent(Event event) override {
241  Clamp();
242  if (!CaptureMouse(event)) {
243  return false;
244  }
245 
246  if (event.is_mouse()) {
247  return OnMouseEvent(event);
248  }
249 
250  if (Focused()) {
251  const int old_selected = selected();
252  if (event == Event::ArrowUp || event == Event::Character('k')) {
253  OnUp();
254  }
255  if (event == Event::ArrowDown || event == Event::Character('j')) {
256  OnDown();
257  }
258  if (event == Event::ArrowLeft || event == Event::Character('h')) {
259  OnLeft();
260  }
261  if (event == Event::ArrowRight || event == Event::Character('l')) {
262  OnRight();
263  }
264  if (event == Event::PageUp) {
265  selected() -= box_.y_max - box_.y_min;
266  }
267  if (event == Event::PageDown) {
268  selected() += box_.y_max - box_.y_min;
269  }
270  if (event == Event::Home) {
271  selected() = 0;
272  }
273  if (event == Event::End) {
274  selected() = size() - 1;
275  }
276  if (event == Event::Tab && size()) {
277  selected() = (selected() + 1) % size();
278  }
279  if (event == Event::TabReverse && size()) {
280  selected() = (selected() + size() - 1) % size();
281  }
282 
283  selected() = util::clamp(selected(), 0, size() - 1);
284 
285  if (selected() != old_selected) {
286  focused_entry() = selected();
287  SelectedTakeFocus();
288  OnChange();
289  return true;
290  }
291  }
292 
293  if (event == Event::Return) {
294  OnEnter();
295  return true;
296  }
297 
298  return false;
299  }
300 
301  bool OnMouseEvent(Event event) {
302  if (event.mouse().button == Mouse::WheelDown ||
303  event.mouse().button == Mouse::WheelUp) {
304  return OnMouseWheel(event);
305  }
306 
307  if (event.mouse().button != Mouse::None &&
308  event.mouse().button != Mouse::Left) {
309  return false;
310  }
311  if (!CaptureMouse(event)) {
312  return false;
313  }
314  for (int i = 0; i < size(); ++i) {
315  if (!boxes_[i].Contain(event.mouse().x, event.mouse().y)) {
316  continue;
317  }
318 
319  TakeFocus();
320  focused_entry() = i;
321 
322  if (event.mouse().button == Mouse::Left &&
323  event.mouse().motion == Mouse::Pressed) {
324  if (selected() != i) {
325  selected() = i;
326  selected_previous_ = selected();
327  OnChange();
328  }
329  return true;
330  }
331  }
332  return false;
333  }
334 
335  bool OnMouseWheel(Event event) {
336  if (!box_.Contain(event.mouse().x, event.mouse().y)) {
337  return false;
338  }
339  const int old_selected = selected();
340 
341  if (event.mouse().button == Mouse::WheelUp) {
342  selected()--;
343  }
344  if (event.mouse().button == Mouse::WheelDown) {
345  selected()++;
346  }
347 
348  selected() = util::clamp(selected(), 0, size() - 1);
349 
350  if (selected() != old_selected) {
351  SelectedTakeFocus();
352  OnChange();
353  }
354  return true;
355  }
356 
357  void UpdateAnimationTarget() {
358  UpdateColorTarget();
359  UpdateUnderlineTarget();
360  }
361 
362  void UpdateColorTarget() {
363  if (size() != int(animation_background_.size())) {
364  animation_background_.resize(size());
365  animation_foreground_.resize(size());
366  animator_background_.clear();
367  animator_foreground_.clear();
368 
369  const int len = size();
370  animator_background_.reserve(len);
371  animator_foreground_.reserve(len);
372  for (int i = 0; i < len; ++i) {
373  animation_background_[i] = 0.F;
374  animation_foreground_[i] = 0.F;
375  animator_background_.emplace_back(&animation_background_[i], 0.F,
376  std::chrono::milliseconds(0),
378  animator_foreground_.emplace_back(&animation_foreground_[i], 0.F,
379  std::chrono::milliseconds(0),
381  }
382  }
383 
384  const bool is_menu_focused = Focused();
385  for (int i = 0; i < size(); ++i) {
386  const bool is_focused = (focused_entry() == i) && is_menu_focused;
387  const bool is_selected = (selected() == i);
388  float target = is_selected ? 1.F : is_focused ? 0.5F : 0.F; // NOLINT
389  if (animator_background_[i].to() != target) {
390  animator_background_[i] = animation::Animator(
391  &animation_background_[i], target,
394  animator_foreground_[i] = animation::Animator(
395  &animation_foreground_[i], target,
398  }
399  }
400  }
401 
402  Decorator AnimatedColorStyle(int i) {
403  Decorator style = nothing;
405  style = style | color(Color::Interpolate(
406  animation_foreground_[i],
409  }
410 
412  style = style | bgcolor(Color::Interpolate(
413  animation_background_[i],
416  }
417  return style;
418  }
419 
420  void UpdateUnderlineTarget() {
421  if (!underline.enabled) {
422  return;
423  }
424 
425  if (FirstTarget() == animator_first_.to() &&
426  SecondTarget() == animator_second_.to()) {
427  return;
428  }
429 
430  if (FirstTarget() >= animator_first_.to()) {
431  animator_first_ = animation::Animator(
432  &first_, FirstTarget(), underline.follower_duration,
434 
435  animator_second_ = animation::Animator(
436  &second_, SecondTarget(), underline.leader_duration,
438  } else {
439  animator_first_ = animation::Animator(
440  &first_, FirstTarget(), underline.leader_duration,
442 
443  animator_second_ = animation::Animator(
444  &second_, SecondTarget(), underline.follower_duration,
446  }
447  }
448 
449  bool Focusable() const final { return entries.size(); }
450  int size() const { return int(entries.size()); }
451  float FirstTarget() {
452  if (boxes_.empty()) {
453  return 0.F;
454  }
455  const int value = IsHorizontal() ? boxes_[selected()].x_min - box_.x_min
456  : boxes_[selected()].y_min - box_.y_min;
457  return float(value);
458  }
459  float SecondTarget() {
460  if (boxes_.empty()) {
461  return 0.F;
462  }
463  const int value = IsHorizontal() ? boxes_[selected()].x_max - box_.x_min
464  : boxes_[selected()].y_max - box_.y_min;
465  return float(value);
466  }
467 
468  protected:
469  int selected_previous_ = selected();
470  int selected_focus_ = selected();
471 
472  // Mouse click support:
473  std::vector<Box> boxes_;
474  Box box_;
475 
476  // Animation support:
477  float first_ = 0.F;
478  float second_ = 0.F;
479  animation::Animator animator_first_ = animation::Animator(&first_, 0.F);
480  animation::Animator animator_second_ = animation::Animator(&second_, 0.F);
481  std::vector<animation::Animator> animator_background_;
482  std::vector<animation::Animator> animator_foreground_;
483  std::vector<float> animation_background_;
484  std::vector<float> animation_foreground_;
485 };
486 
487 /// @brief A list of text. The focused element is selected.
488 /// @param option a structure containing all the paramters.
489 /// @ingroup component
490 ///
491 /// ### Example
492 ///
493 /// ```cpp
494 /// auto screen = ScreenInteractive::TerminalOutput();
495 /// std::vector<std::string> entries = {
496 /// "entry 1",
497 /// "entry 2",
498 /// "entry 3",
499 /// };
500 /// int selected = 0;
501 /// auto menu = Menu({
502 /// .entries = &entries,
503 /// .selected = &selected,
504 /// });
505 /// screen.Loop(menu);
506 /// ```
507 ///
508 /// ### Output
509 ///
510 /// ```bash
511 /// > entry 1
512 /// entry 2
513 /// entry 3
514 /// ```
516  return Make<MenuBase>(std::move(option));
517 }
518 
519 /// @brief A list of text. The focused element is selected.
520 /// @param entries The list of entries in the menu.
521 /// @param selected The index of the currently selected element.
522 /// @param option Additional optional parameters.
523 /// @ingroup component
524 ///
525 /// ### Example
526 ///
527 /// ```cpp
528 /// auto screen = ScreenInteractive::TerminalOutput();
529 /// std::vector<std::string> entries = {
530 /// "entry 1",
531 /// "entry 2",
532 /// "entry 3",
533 /// };
534 /// int selected = 0;
535 /// auto menu = Menu(&entries, &selected);
536 /// screen.Loop(menu);
537 /// ```
538 ///
539 /// ### Output
540 ///
541 /// ```bash
542 /// > entry 1
543 /// entry 2
544 /// entry 3
545 /// ```
546 Component Menu(ConstStringListRef entries, int* selected, MenuOption option) {
547  option.entries = entries;
548  option.selected = selected;
549  return Menu(std::move(option));
550 }
551 
552 /// @brief An horizontal list of elements. The user can navigate through them.
553 /// @param entries The list of selectable entries to display.
554 /// @param selected Reference the selected entry.
555 /// See also |Menu|.
556 /// @ingroup component
557 Component Toggle(ConstStringListRef entries, int* selected) {
558  return Menu(entries, selected, MenuOption::Toggle());
559 }
560 
561 /// @brief A specific menu entry. They can be put into a Container::Vertical to
562 /// form a menu.
563 /// @param label The text drawn representing this element.
564 /// @param option Additional optional parameters.
565 /// @ingroup component
566 ///
567 /// ### Example
568 ///
569 /// ```cpp
570 /// auto screen = ScreenInteractive::TerminalOutput();
571 /// int selected = 0;
572 /// auto menu = Container::Vertical({
573 /// MenuEntry("entry 1"),
574 /// MenuEntry("entry 2"),
575 /// MenuEntry("entry 3"),
576 /// }, &selected);
577 /// screen.Loop(menu);
578 /// ```
579 ///
580 /// ### Output
581 ///
582 /// ```bash
583 /// > entry 1
584 /// entry 2
585 /// entry 3
586 /// ```
588  option.label = label;
589  return MenuEntry(std::move(option));
590 }
591 
592 /// @brief A specific menu entry. They can be put into a Container::Vertical to
593 /// form a menu.
594 /// @param option The parameters.
595 /// @ingroup component
596 ///
597 /// ### Example
598 ///
599 /// ```cpp
600 /// auto screen = ScreenInteractive::TerminalOutput();
601 /// int selected = 0;
602 /// auto menu = Container::Vertical({
603 /// MenuEntry({.label = "entry 1"}),
604 /// MenuEntry({.label = "entry 2"}),
605 /// MenuEntry({.label = "entry 3"}),
606 /// }, &selected);
607 /// screen.Loop(menu);
608 /// ```
609 ///
610 /// ### Output
611 ///
612 /// ```bash
613 /// > entry 1
614 /// entry 2
615 /// entry 3
616 /// ```
618  class Impl : public ComponentBase, public MenuEntryOption {
619  public:
620  explicit Impl(MenuEntryOption option)
621  : MenuEntryOption(std::move(option)) {}
622 
623  private:
624  Element Render() override {
625  const bool focused = Focused();
626  UpdateAnimationTarget();
627 
628  const EntryState state = {
629  label(),
630  false,
631  hovered_,
632  focused,
633  };
634 
635  const Element element =
636  (transform ? transform : DefaultOptionTransform) //
637  (state);
638 
639  auto focus_management = focused ? select : nothing;
640  return element | AnimatedColorStyle() | focus_management | reflect(box_);
641  }
642 
643  void UpdateAnimationTarget() {
644  const bool focused = Focused();
645  float target = focused ? 1.F : hovered_ ? 0.5F : 0.F; // NOLINT
646  if (target == animator_background_.to()) {
647  return;
648  }
649  animator_background_ = animation::Animator(
650  &animation_background_, target, animated_colors.background.duration,
651  animated_colors.background.function);
652  animator_foreground_ = animation::Animator(
653  &animation_foreground_, target, animated_colors.foreground.duration,
654  animated_colors.foreground.function);
655  }
656 
657  Decorator AnimatedColorStyle() {
658  Decorator style = nothing;
659  if (animated_colors.foreground.enabled) {
660  style = style |
661  color(Color::Interpolate(animation_foreground_,
662  animated_colors.foreground.inactive,
663  animated_colors.foreground.active));
664  }
665 
666  if (animated_colors.background.enabled) {
667  style = style |
668  bgcolor(Color::Interpolate(animation_background_,
669  animated_colors.background.inactive,
670  animated_colors.background.active));
671  }
672  return style;
673  }
674 
675  bool Focusable() const override { return true; }
676  bool OnEvent(Event event) override {
677  if (!event.is_mouse()) {
678  return false;
679  }
680 
681  hovered_ = box_.Contain(event.mouse().x, event.mouse().y);
682 
683  if (!hovered_) {
684  return false;
685  }
686 
687  if (event.mouse().button == Mouse::Left &&
688  event.mouse().motion == Mouse::Pressed) {
689  TakeFocus();
690  return true;
691  }
692 
693  return false;
694  }
695 
696  void OnAnimation(animation::Params& params) override {
697  animator_background_.OnAnimation(params);
698  animator_foreground_.OnAnimation(params);
699  }
700 
701  MenuEntryOption option_;
702  Box box_;
703  bool hovered_ = false;
704 
705  float animation_background_ = 0.F;
706  float animation_foreground_ = 0.F;
707  animation::Animator animator_background_ =
708  animation::Animator(&animation_background_, 0.F);
709  animation::Animator animator_foreground_ =
710  animation::Animator(&animation_foreground_, 0.F);
711  };
712 
713  return Make<Impl>(std::move(option));
714 }
715 
716 } // namespace ftxui
static Color Interpolate(float t, const Color &a, const Color &b)
Definition: color.cpp:176
It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ft...
bool Focused() const
Returns if the elements if focused by the user. True when the ComponentBase is focused by the user....
Definition: component.cpp:161
CapturedMouse CaptureMouse(const Event &event)
Take the CapturedMouse if available. There is only one component of them. It represents a component t...
Definition: component.cpp:195
void TakeFocus()
Configure all the ancestors to give focus to this component.
Definition: component.cpp:183
An adapter. Reference a list of strings.
Definition: ref.hpp:98
size_t size() const
Definition: ref.hpp:106
An adapter. Own or reference a constant string. For convenience, this class convert multiple immutabl...
Definition: ref.hpp:86
float Linear(float p)
Modeled after the line y = x.
Definition: animation.cpp:30
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
Definition: util.hpp:12
Decorator bgcolor(Color)
Decorate using a background color.
Definition: color.cpp:105
Element xflex(Element)
Expand/Minimize if possible/needed on the X axis.
Definition: flex.cpp:129
std::function< Element(Element)> Decorator
Definition: elements.hpp:25
Element separatorVSelector(float up, float down, Color unselected_color, Color selected_color)
Draw an vertical bar, with the area in between up/downcolored differently.
Definition: separator.cpp:510
AnimatedColorOption foreground
Element nothing(Element element)
A decoration doing absolutely nothing.
Definition: util.cpp:30
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Definition: size.cpp:90
Direction
Definition: direction.hpp:8
std::shared_ptr< Node > Element
Definition: elements.hpp:23
Component Menu(MenuOption options)
A list of text. The focused element is selected.
Definition: menu.cpp:515
Component MenuEntry(MenuEntryOption options)
A specific menu entry. They can be put into a Container::Vertical to form a menu.
Definition: menu.cpp:617
std::shared_ptr< ComponentBase > Component
Component Toggle(ConstStringListRef entries, int *selected)
An horizontal list of elements. The user can navigate through them.
Definition: menu.cpp:557
Element bold(Element)
Use a bold font, for elements with more emphasis.
Definition: bold.cpp:33
Element yflex(Element)
Expand/Minimize if possible/needed on the Y axis.
Definition: flex.cpp:135
Element separatorHSelector(float left, float right, Color unselected_color, Color selected_color)
Draw an horizontal bar, with the area in between left/right colored differently.
Definition: separator.cpp:440
AnimatedColorOption background
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition: hbox.cpp:83
std::function< Element(const EntryState &state)> transform
Element inverted(Element)
Add a filter that will invert the foreground and the background colors.
Definition: inverted.cpp:34
Element text(std::wstring text)
Display a piece of unicode text.
Definition: text.cpp:120
std::vector< Element > Elements
Definition: elements.hpp:24
Element select(Element)
Set the child to be the one selected among its siblings.
Definition: frame.cpp:150
Element focus(Element)
Set the child to be the one in focus globally.
Definition: frame.cpp:157
Decorator reflect(Box &box)
Definition: reflect.cpp:44
AnimatedColorsOption animated_colors
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Definition: node.cpp:47
Decorator color(Color)
Decorate using a foreground color.
Definition: color.cpp:91
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition: vbox.cpp:83
arguments for |ButtonOption::transform|, |CheckboxOption::transform|, |Radiobox::transform|,...
Option for the MenuEntry component.
animation::easing::Function function
animation::Duration duration
Represent an event. It can be key press event, a terminal resize, or more ...
Definition: event.hpp:29
static const Event TabReverse
Definition: event.hpp:56
static const Event PageUp
Definition: event.hpp:63
bool is_mouse() const
Definition: event.hpp:78
static Event Character(std::string)
An event corresponding to a given typed character.
Definition: event.cpp:16
static const Event ArrowUp
Definition: event.hpp:42
static const Event Tab
Definition: event.hpp:55
static const Event ArrowDown
Definition: event.hpp:43
static const Event End
Definition: event.hpp:61
static const Event Home
Definition: event.hpp:60
struct Mouse & mouse()
Definition: event.hpp:79
static const Event PageDown
Definition: event.hpp:64
static const Event Return
Definition: event.hpp:53
static const Event ArrowLeft
Definition: event.hpp:40
static const Event ArrowRight
Definition: event.hpp:41
Option for the Menu component.
std::function< Element()> elements_prefix
static MenuOption Toggle()
Standard options for a horitontal menu with some separator. This can be useful to implement a tab bar...
MenuEntryOption entries_option
std::function< void()> on_enter
Called when the selected entry changes.
UnderlineOption underline
The index of the selected entry.
ConstStringListRef entries
Ref< int > focused_entry
Called when the user presses enter.
std::function< Element()> elements_infix
std::function< Element()> elements_postfix
std::function< void()> on_change
Ref< int > selected
The list of entries.
Button button
Definition: mouse.hpp:28
Motion motion
Definition: mouse.hpp:31
animation::Duration follower_duration
animation::easing::Function leader_function
animation::Duration follower_delay
animation::Duration leader_duration
animation::easing::Function follower_function
animation::Duration leader_delay