From 9b658980b28cef5d3dd333f4c25ce3f035e49d3e Mon Sep 17 00:00:00 2001 From: Michael Davidson Date: Fri, 29 Dec 2023 18:37:36 +1100 Subject: [PATCH] Add [horizontal|vertical]_child_align_to_string methods Used as part of ESP_LOGCONFIG() to aide in human readability --- .../graphical_layout/horizontal_stack.cpp | 2 +- .../graphical_layout/layout_item.cpp | 30 +++++++++++++++++++ .../components/graphical_layout/layout_item.h | 4 +++ .../graphical_layout/vertical_stack.cpp | 2 +- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/esphome/components/graphical_layout/horizontal_stack.cpp b/esphome/components/graphical_layout/horizontal_stack.cpp index ef528e7bfc..e17ad3173b 100644 --- a/esphome/components/graphical_layout/horizontal_stack.cpp +++ b/esphome/components/graphical_layout/horizontal_stack.cpp @@ -11,7 +11,7 @@ static const char *const TAG = "horizontalstack"; void HorizontalStack::dump_config(int indent_depth, int additional_level_depth) { ESP_LOGCONFIG(TAG, "%*sItem Padding: %i", indent_depth, "", this->item_padding_); - ESP_LOGCONFIG(TAG, "%*sChild alignment: %i", indent_depth, "", (int) this->child_align_); + ESP_LOGCONFIG(TAG, "%*sChild alignment: %s", indent_depth, "", vertical_child_align_to_string(this->child_align_)); ESP_LOGCONFIG(TAG, "%*sChildren: %i", indent_depth, "", this->children_.size()); for (LayoutItem *child : this->children_) { diff --git a/esphome/components/graphical_layout/layout_item.cpp b/esphome/components/graphical_layout/layout_item.cpp index 3d44302b05..dca3bcdfbc 100644 --- a/esphome/components/graphical_layout/layout_item.cpp +++ b/esphome/components/graphical_layout/layout_item.cpp @@ -55,5 +55,35 @@ void LayoutItem::render(display::Display *display, display::Rect bounds) { display->pop_local_coordinates(); } +const LogString *horizontal_child_align_to_string(HorizontalChildAlign align) { + switch (align) { + case HorizontalChildAlign::LEFT: + return LOG_STR("LEFT"); + case HorizontalChildAlign::CENTER_HORIZONTAL: + return LOG_STR("CENTER_HORIZONTAL"); + case HorizontalChildAlign::RIGHT: + return LOG_STR("RIGHT"); + case HorizontalChildAlign::STRETCH_TO_FIT_WIDTH: + return LOG_STR("STRETCH_TO_FIT_WIDTH"); + default: + return LOG_STR("UNKNOWN"); + } +} + +const LogString *vertical_child_align_to_string(VerticalChildAlign align){ + switch (align) { + case VerticalChildAlign::TOP: + return LOG_STR("TOP"); + case VerticalChildAlign::CENTER_VERTICAL: + return LOG_STR("CENTER_VERTICAL"); + case VerticalChildAlign::BOTTOM: + return LOG_STR("BOTTOM"); + case VerticalChildAlign::STRETCH_TO_FIT_HEIGHT: + return LOG_STR("STRETCH_TO_FIT_HEIGHT"); + default: + return LOG_STR("UNKNOWN"); + } +} + } // namespace graphical_layout } // namespace esphome diff --git a/esphome/components/graphical_layout/layout_item.h b/esphome/components/graphical_layout/layout_item.h index 3b221ac103..9c65120091 100644 --- a/esphome/components/graphical_layout/layout_item.h +++ b/esphome/components/graphical_layout/layout_item.h @@ -1,6 +1,7 @@ #pragma once #include "esphome/core/color.h" +#include "esphome/core/log.h" namespace esphome { namespace display { @@ -100,5 +101,8 @@ class LayoutItem { Color border_color_{Color(0, 0, 0, 0)}; }; +const LogString *horizontal_child_align_to_string(HorizontalChildAlign align); +const LogString *vertical_child_align_to_string(VerticalChildAlign align); + } // namespace graphical_layout } // namespace esphome diff --git a/esphome/components/graphical_layout/vertical_stack.cpp b/esphome/components/graphical_layout/vertical_stack.cpp index c287784665..9c020db176 100644 --- a/esphome/components/graphical_layout/vertical_stack.cpp +++ b/esphome/components/graphical_layout/vertical_stack.cpp @@ -11,7 +11,7 @@ static const char *const TAG = "verticalstack"; void VerticalStack::dump_config(int indent_depth, int additional_level_depth) { ESP_LOGCONFIG(TAG, "%*sItem Padding: %i", indent_depth, "", this->item_padding_); - ESP_LOGCONFIG(TAG, "%*sChild alignment: %i", indent_depth, "", (int) this->child_align_); + ESP_LOGCONFIG(TAG, "%*sChild alignment: %s", indent_depth, "", horizontal_child_align_to_string(this->child_align_)); ESP_LOGCONFIG(TAG, "%*sChildren: %i", indent_depth, "", this->children_.size()); for (LayoutItem *child : this->children_) {