From 982942a51209379d64065b9da27874c61d96da0f Mon Sep 17 00:00:00 2001 From: Michael Davidson Date: Fri, 29 Dec 2023 18:31:01 +1100 Subject: [PATCH] Add text_align_to_string Used for debugging ESP_LOGCONFIG purposes --- esphome/components/display/display.cpp | 31 ++++++++++++++++++++++++++ esphome/components/display/display.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/esphome/components/display/display.cpp b/esphome/components/display/display.cpp index 3171f49223..ff97c8b322 100644 --- a/esphome/components/display/display.cpp +++ b/esphome/components/display/display.cpp @@ -416,5 +416,36 @@ void DisplayPage::set_prev(DisplayPage *prev) { this->prev_ = prev; } void DisplayPage::set_next(DisplayPage *next) { this->next_ = next; } const display_writer_t &DisplayPage::get_writer() const { return this->writer_; } +const LogString *text_align_to_string(TextAlign textalign) { + switch (textalign) { + case TextAlign::TOP_LEFT: + return LOG_STR("TOP_LEFT"); + case TextAlign::TOP_CENTER: + return LOG_STR("TOP_CENTER"); + case TextAlign::TOP_RIGHT: + return LOG_STR("TOP_RIGHT"); + case TextAlign::CENTER_LEFT: + return LOG_STR("CENTER_LEFT"); + case TextAlign::CENTER: + return LOG_STR("CENTER"); + case TextAlign::CENTER_RIGHT: + return LOG_STR("CENTER_RIGHT"); + case TextAlign::BASELINE_LEFT: + return LOG_STR("BASELINE_LEFT"); + case TextAlign::BASELINE_CENTER: + return LOG_STR("BASELINE_CENTER"); + case TextAlign::BASELINE_RIGHT: + return LOG_STR("BASELINE_RIGHT"); + case TextAlign::BOTTOM_LEFT: + return LOG_STR("BOTTOM_LEFT"); + case TextAlign::BOTTOM_CENTER: + return LOG_STR("BOTTOM_CENTER"); + case TextAlign::BOTTOM_RIGHT: + return LOG_STR("BOTTOM_RIGHT"); + default: + return LOG_STR("UNKNOWN"); + } +} + } // namespace display } // namespace esphome diff --git a/esphome/components/display/display.h b/esphome/components/display/display.h index a38922a663..595a8bf0d0 100644 --- a/esphome/components/display/display.h +++ b/esphome/components/display/display.h @@ -9,6 +9,7 @@ #include "esphome/core/color.h" #include "esphome/core/automation.h" #include "esphome/core/time.h" +#include "esphome/core/log.h" #ifdef USE_GRAPH #include "esphome/components/graph/graph.h" @@ -631,5 +632,7 @@ class DisplayOnPageChangeTrigger : public Trigger DisplayPage *to_{nullptr}; }; +const LogString *text_align_to_string(TextAlign textalign); + } // namespace display } // namespace esphome