ESPHome  2024.10.2
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  virtual void on_before_show(){};
64  virtual void on_after_show(){};
65  virtual void on_before_hide(){};
66  virtual void on_after_hide(){};
67 
68  uint8_t rows_;
69  bool active_;
72 
74  uint8_t top_index_{0};
75  uint8_t cursor_index_{0};
76  std::forward_list<std::pair<uint8_t, uint8_t>> selection_stack_{};
77  bool editing_{false};
78  bool root_on_enter_called_{false};
79 };
80 
81 } // namespace display_menu_base
82 } // 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:183
const float PROCESSOR
For components that use data from sensors like displays.
Definition: component.cpp:20
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Class to display a hierarchical menu.