1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-29 08:32:26 +01:00

Add graphical display menu (#4105)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
Co-authored-by: Alex Hermann <gaaf@gmx.net>
This commit is contained in:
Michael Davidson
2023-12-12 14:15:59 +11:00
committed by GitHub
parent 86e6a8a503
commit b30430b0bd
12 changed files with 598 additions and 9 deletions

View File

@@ -172,6 +172,8 @@ void DisplayMenuComponent::show_main() {
this->process_initial_();
this->on_before_show();
if (this->active_ && this->editing_)
this->finish_editing_();
@@ -188,6 +190,8 @@ void DisplayMenuComponent::show_main() {
}
this->draw_and_update();
this->on_after_show();
}
void DisplayMenuComponent::show() {
@@ -196,18 +200,26 @@ void DisplayMenuComponent::show() {
this->process_initial_();
this->on_before_show();
if (!this->active_) {
this->active_ = true;
this->draw_and_update();
}
this->on_after_show();
}
void DisplayMenuComponent::hide() {
if (this->check_healthy_and_active_()) {
this->on_before_hide();
if (this->editing_)
this->finish_editing_();
this->active_ = false;
this->update();
this->on_after_hide();
}
}

View File

@@ -60,6 +60,11 @@ class DisplayMenuComponent : public Component {
update();
}
virtual void on_before_show(){};
virtual void on_after_show(){};
virtual void on_before_hide(){};
virtual void on_after_hide(){};
uint8_t rows_;
bool active_;
MenuMode mode_;

View File

@@ -5,6 +5,29 @@
namespace esphome {
namespace display_menu_base {
const LogString *menu_item_type_to_string(MenuItemType type) {
switch (type) {
case MenuItemType::MENU_ITEM_LABEL:
return LOG_STR("MENU_ITEM_LABEL");
case MenuItemType::MENU_ITEM_MENU:
return LOG_STR("MENU_ITEM_MENU");
case MenuItemType::MENU_ITEM_BACK:
return LOG_STR("MENU_ITEM_BACK");
case MenuItemType::MENU_ITEM_SELECT:
return LOG_STR("MENU_ITEM_SELECT");
case MenuItemType::MENU_ITEM_NUMBER:
return LOG_STR("MENU_ITEM_NUMBER");
case MenuItemType::MENU_ITEM_SWITCH:
return LOG_STR("MENU_ITEM_SWITCH");
case MenuItemType::MENU_ITEM_COMMAND:
return LOG_STR("MENU_ITEM_COMMAND");
case MenuItemType::MENU_ITEM_CUSTOM:
return LOG_STR("MENU_ITEM_CUSTOM");
default:
return LOG_STR("UNKNOWN");
}
}
void MenuItem::on_enter() { this->on_enter_callbacks_.call(); }
void MenuItem::on_leave() { this->on_leave_callbacks_.call(); }

View File

@@ -14,6 +14,7 @@
#endif
#include <vector>
#include "esphome/core/log.h"
namespace esphome {
namespace display_menu_base {
@@ -29,6 +30,9 @@ enum MenuItemType {
MENU_ITEM_CUSTOM,
};
/// @brief Returns a string representation of a menu item type suitable for logging
const LogString *menu_item_type_to_string(MenuItemType type);
class MenuItem;
class MenuItemMenu;
using value_getter_t = std::function<std::string(const MenuItem *)>;