From fed36a0af5653d7f939524d988c39097c1d840e7 Mon Sep 17 00:00:00 2001 From: Michael Davidson Date: Sun, 31 Dec 2023 09:31:51 +1100 Subject: [PATCH] Add dump_config_base_properties to LayoutItem - displays the basic properties of the item (Margin, Border, Padding) --- esphome/components/graphical_layout/__init__.py | 2 +- .../graphical_layout/display_rendering_panel.cpp | 1 + .../components/graphical_layout/fixed_dimension_panel.cpp | 2 +- esphome/components/graphical_layout/horizontal_stack.cpp | 1 + esphome/components/graphical_layout/layout_item.cpp | 8 ++++++++ esphome/components/graphical_layout/layout_item.h | 7 +++++++ esphome/components/graphical_layout/text_panel.cpp | 1 + esphome/components/graphical_layout/text_run_panel.cpp | 1 + esphome/components/graphical_layout/vertical_stack.cpp | 1 + 9 files changed, 22 insertions(+), 2 deletions(-) diff --git a/esphome/components/graphical_layout/__init__.py b/esphome/components/graphical_layout/__init__.py index d91b707661..46910315e8 100644 --- a/esphome/components/graphical_layout/__init__.py +++ b/esphome/components/graphical_layout/__init__.py @@ -93,7 +93,7 @@ async def build_layout_item_pvariable(config): cg.add(var.set_border_color(border_color)) padding = await cg.templatable(config[CONF_PADDING], args=[], output_type=int) - cg.add(var.set_margin(padding)) + cg.add(var.set_padding(padding)) return var diff --git a/esphome/components/graphical_layout/display_rendering_panel.cpp b/esphome/components/graphical_layout/display_rendering_panel.cpp index 03d01906ae..c6c40390a5 100644 --- a/esphome/components/graphical_layout/display_rendering_panel.cpp +++ b/esphome/components/graphical_layout/display_rendering_panel.cpp @@ -10,6 +10,7 @@ namespace graphical_layout { static const char *const TAG = "displayrenderingpanel"; void DisplayRenderingPanel::dump_config(int indent_depth, int additional_level_depth) { + this->dump_config_base_properties(TAG, indent_depth); ESP_LOGCONFIG(TAG, "%*sDimensions: %ix%i", indent_depth, "", this->width_.value(), this->height_.value()); ESP_LOGCONFIG(TAG, "%*sHas drawing lambda: %s", indent_depth, "", YESNO(this->lambda_ != nullptr)); } diff --git a/esphome/components/graphical_layout/fixed_dimension_panel.cpp b/esphome/components/graphical_layout/fixed_dimension_panel.cpp index 784bd377ef..c768da06ef 100644 --- a/esphome/components/graphical_layout/fixed_dimension_panel.cpp +++ b/esphome/components/graphical_layout/fixed_dimension_panel.cpp @@ -10,7 +10,7 @@ namespace graphical_layout { static const char *const TAG = "fixeddimensionpanel"; void FixedDimensionPanel::dump_config(int indent_depth, int additional_level_depth) { - ESP_LOGCONFIG(TAG, "%*sWidth: %i (Will use display width: %s)", indent_depth, "", this->width_.value(), + this->dump_config_base_properties(TAG, indent_depth); YESNO(this->width_.value() < 1)); ESP_LOGCONFIG(TAG, "%*sHeight: %i (Will use display height: %s)", indent_depth, "", this->height_.value(), YESNO(this->height_.value() < 1)); diff --git a/esphome/components/graphical_layout/horizontal_stack.cpp b/esphome/components/graphical_layout/horizontal_stack.cpp index c26ee2a741..3a11c07878 100644 --- a/esphome/components/graphical_layout/horizontal_stack.cpp +++ b/esphome/components/graphical_layout/horizontal_stack.cpp @@ -10,6 +10,7 @@ namespace graphical_layout { static const char *const TAG = "horizontalstack"; void HorizontalStack::dump_config(int indent_depth, int additional_level_depth) { + this->dump_config_base_properties(TAG, indent_depth); ESP_LOGCONFIG(TAG, "%*sItem Padding: %i", indent_depth, "", this->item_padding_); ESP_LOGCONFIG(TAG, "%*sChild alignment: %s", indent_depth, "", LOG_STR_ARG(vertical_child_align_to_string(this->child_align_))); diff --git a/esphome/components/graphical_layout/layout_item.cpp b/esphome/components/graphical_layout/layout_item.cpp index 7f65746979..e4c43c01e9 100644 --- a/esphome/components/graphical_layout/layout_item.cpp +++ b/esphome/components/graphical_layout/layout_item.cpp @@ -55,6 +55,14 @@ void LayoutItem::render(display::Display *display, display::Rect bounds) { display->pop_local_coordinates(); } +void LayoutItem::dump_config_base_properties(const char *tag, int indent_depth) { + ESP_LOGCONFIG(tag, "%*sMargin: %i", indent_depth, "", this->margin_); + ESP_LOGCONFIG(tag, "%*sBorder: %i", indent_depth, "", this->border_); + ESP_LOGCONFIG(tag, "%*sBorder Color: (R: %i, G: %i, B: %i)", indent_depth, "", this->border_color_.r, + this->border_color_.g, this->border_color_.b); + ESP_LOGCONFIG(tag, "%*sPadding: %i", indent_depth, "", this->padding_); +} + const LogString *horizontal_child_align_to_string(HorizontalChildAlign align) { switch (align) { case HorizontalChildAlign::LEFT: diff --git a/esphome/components/graphical_layout/layout_item.h b/esphome/components/graphical_layout/layout_item.h index c50cbd8864..9274ba0b84 100644 --- a/esphome/components/graphical_layout/layout_item.h +++ b/esphome/components/graphical_layout/layout_item.h @@ -84,6 +84,13 @@ class LayoutItem { */ virtual void dump_config(int indent_depth, int additional_level_depth) = 0; + /** Dumps the base properties of the LayoutItem. Should be called by implementors dump_config() + * + * param[in] tag: Tag to pass to ESP_LOGCONFIG + * param[in] indent_depth: Depth to indent the config + */ + void dump_config_base_properties(const char *tag, int indent_depth); + /** Called once all setup has been completed (i.e. after code generation and all your set_ methods * have been called). Can be used to finalise any configuration */ diff --git a/esphome/components/graphical_layout/text_panel.cpp b/esphome/components/graphical_layout/text_panel.cpp index 0a35394c05..9ef02451a7 100644 --- a/esphome/components/graphical_layout/text_panel.cpp +++ b/esphome/components/graphical_layout/text_panel.cpp @@ -13,6 +13,7 @@ static const int TEXT_ALIGN_Y_MASK = (int) display::TextAlign::BOTTOM | (int) display::TextAlign::BASELINE | (int) display::TextAlign::CENTER_VERTICAL; void TextPanel::dump_config(int indent_depth, int additional_level_depth) { + this->dump_config_base_properties(TAG, indent_depth); std::string text = this->text_.value(); ESP_LOGCONFIG(TAG, "%*sText Align: %s", indent_depth, "", LOG_STR_ARG(display::text_align_to_string(this->text_align_))); diff --git a/esphome/components/graphical_layout/text_run_panel.cpp b/esphome/components/graphical_layout/text_run_panel.cpp index 33563960fc..685c6a1751 100644 --- a/esphome/components/graphical_layout/text_run_panel.cpp +++ b/esphome/components/graphical_layout/text_run_panel.cpp @@ -13,6 +13,7 @@ static const int TEXT_ALIGN_Y_MASK = (int) display::TextAlign::BOTTOM | (int) display::TextAlign::BASELINE | (int) display::TextAlign::CENTER_VERTICAL; void TextRunPanel::dump_config(int indent_depth, int additional_level_depth) { + this->dump_config_base_properties(TAG, indent_depth); ESP_LOGCONFIG(TAG, "%*sMin Width: %i", indent_depth, "", this->min_width_); ESP_LOGCONFIG(TAG, "%*sMax Width: %i", indent_depth, "", this->max_width_); ESP_LOGCONFIG(TAG, "%*sText Align: %s", indent_depth, "", diff --git a/esphome/components/graphical_layout/vertical_stack.cpp b/esphome/components/graphical_layout/vertical_stack.cpp index acc72a9996..dea36a878d 100644 --- a/esphome/components/graphical_layout/vertical_stack.cpp +++ b/esphome/components/graphical_layout/vertical_stack.cpp @@ -10,6 +10,7 @@ namespace graphical_layout { static const char *const TAG = "verticalstack"; void VerticalStack::dump_config(int indent_depth, int additional_level_depth) { + this->dump_config_base_properties(TAG, indent_depth); ESP_LOGCONFIG(TAG, "%*sItem Padding: %i", indent_depth, "", this->item_padding_); ESP_LOGCONFIG(TAG, "%*sChild alignment: %s", indent_depth, "", LOG_STR_ARG(horizontal_child_align_to_string(this->child_align_)));