ESPHome  2023.3.1
display_menu_base.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include "menu_item.h"
6 
7 #include <forward_list>
8 
9 namespace esphome {
10 namespace display_menu_base {
11 
12 enum MenuMode {
15 };
16 
17 class MenuItem;
18 
23  public:
24  void set_root_item(MenuItemMenu *item) { this->displayed_item_ = this->root_item_ = item; }
25  void set_active(bool active) { this->active_ = active; }
26  void set_mode(MenuMode mode) { this->mode_ = mode; }
27  void set_rows(uint8_t rows) { this->rows_ = rows; }
28 
29  float get_setup_priority() const override { return setup_priority::PROCESSOR; }
30 
31  void up();
32  void down();
33  void left();
34  void right();
35  void enter();
36 
37  void show_main();
38  void show();
39  void hide();
40 
41  void draw();
42 
43  bool is_active() const { return this->active_; }
44 
45  protected:
46  void reset_();
47  void process_initial_();
50  bool cursor_up_();
51  bool cursor_down_();
52  bool enter_menu_();
53  bool leave_menu_();
54  void finish_editing_();
55  virtual void draw_menu();
56  virtual void draw_item(const MenuItem *item, uint8_t row, bool selected) = 0;
57  virtual void update() {}
58  virtual void draw_and_update() {
59  draw_menu();
60  update();
61  }
62 
63  uint8_t rows_;
64  bool active_;
67 
69  uint8_t top_index_{0};
70  uint8_t cursor_index_{0};
71  std::forward_list<std::pair<uint8_t, uint8_t>> selection_stack_{};
72  bool editing_{false};
73  bool root_on_enter_called_{false};
74 };
75 
76 } // namespace display_menu_base
77 } // namespace esphome
virtual void draw_item(const MenuItem *item, uint8_t row, bool selected)=0
std::forward_list< std::pair< uint8_t, uint8_t > > selection_stack_
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:151
const float PROCESSOR
For components that use data from sensors like displays.
Definition: component.cpp:19
Definition: a4988.cpp:4
Class to display a hierarchical menu.