mirror of
https://github.com/esphome/esphome.git
synced 2024-12-12 08:24:55 +01:00
Apply flake8. pylint, ci-custom, and clang-format fixes
This commit is contained in:
parent
93d2e4e8ff
commit
4046d9e074
7 changed files with 92 additions and 80 deletions
|
@ -10,9 +10,10 @@ namespace graphical_layout {
|
||||||
static const char *const TAG = "fixeddimensionpanel";
|
static const char *const TAG = "fixeddimensionpanel";
|
||||||
|
|
||||||
void FixedDimensionPanel::dump_config(int indent_depth, int additional_level_depth) {
|
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(), YESNO(this->width_.value() < 1));
|
ESP_LOGCONFIG(TAG, "%*sWidth: %i (Will use display width: %s)", indent_depth, "", this->width_.value(),
|
||||||
ESP_LOGCONFIG(TAG, "%*sHeight: %i (Will use display height: %s)", indent_depth, "", this->height_.value(), YESNO(this->height_.value() < 1));
|
YESNO(this->width_.value() < 1));
|
||||||
ESP_LOGCONFIG(TAG, "%*sHas Child: %s", indent_depth, "", YESNO(this->child_ != nullptr));
|
+ ESP_LOGCONFIG(TAG, "%*sHeight: %i (Will use display height: %s)", indent_depth, "", this->height_.value(),
|
||||||
|
YESNO(this->height_.value() < 1));
|
||||||
this->child_->dump_config(indent_depth + additional_level_depth, additional_level_depth);
|
this->child_->dump_config(indent_depth + additional_level_depth, additional_level_depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ namespace graphical_layout {
|
||||||
static const char *const TAG = "rootlayoutcomponent";
|
static const char *const TAG = "rootlayoutcomponent";
|
||||||
|
|
||||||
void RootLayoutComponent::setup() {
|
void RootLayoutComponent::setup() {
|
||||||
|
ESP_LOGD(TAG, "Calling setup_complete on layout_root");
|
||||||
this->layout_root_->setup_complete();
|
this->layout_root_->setup_complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,8 @@ void TextRunPanel::setup_complete() {
|
||||||
}
|
}
|
||||||
|
|
||||||
display::Rect TextRunPanel::measure_item_internal(display::Display *display) {
|
display::Rect TextRunPanel::measure_item_internal(display::Display *display) {
|
||||||
CalculatedLayout calculated = this->determine_layout(display, display::Rect(0, 0, this->max_width_, display->get_height()), true);
|
CalculatedLayout calculated =
|
||||||
|
this->determine_layout(display, display::Rect(0, 0, this->max_width_, display->get_height()), true);
|
||||||
return calculated.bounds;
|
return calculated.bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,9 +44,11 @@ void TextRunPanel::render_internal(display::Display *display, display::Rect boun
|
||||||
|
|
||||||
for (auto calculated : layout.runs) {
|
for (auto calculated : layout.runs) {
|
||||||
if (calculated->run->background_color_ != display::COLOR_OFF) {
|
if (calculated->run->background_color_ != display::COLOR_OFF) {
|
||||||
display->filled_rectangle(calculated->bounds.x, calculated->bounds.y, calculated->bounds.w, calculated->bounds.h, calculated->run->background_color_);
|
display->filled_rectangle(calculated->bounds.x, calculated->bounds.y, calculated->bounds.w, calculated->bounds.h,
|
||||||
|
calculated->run->background_color_);
|
||||||
}
|
}
|
||||||
display->print(calculated->bounds.x, calculated->bounds.y, calculated->run->font_, calculated->run->foreground_color_, display::TextAlign::TOP_LEFT, calculated->text_.c_str());
|
display->print(calculated->bounds.x, calculated->bounds.y, calculated->run->font_,
|
||||||
|
calculated->run->foreground_color_, display::TextAlign::TOP_LEFT, calculated->text_.c_str()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->debug_outline_runs_) {
|
if (this->debug_outline_runs_) {
|
||||||
|
@ -78,10 +81,10 @@ CalculatedLayout TextRunPanel::determine_layout(display::Display *display, displ
|
||||||
|
|
||||||
if ((x_offset + width) < bounds.w) {
|
if ((x_offset + width) < bounds.w) {
|
||||||
// Item fits on the current line
|
// Item fits on the current line
|
||||||
auto calculated = std::make_shared<CalculatedTextRun>(run, text, display::Rect(x_offset, y_offset, width, height), baseline, line_number);
|
auto calculated = std::make_shared<CalculatedTextRun>(run, text, display::Rect(x_offset, y_offset, width, height),
|
||||||
|
baseline, line_number);
|
||||||
calculated_layout.runs.push_back(calculated);
|
calculated_layout.runs.push_back(calculated);
|
||||||
|
|
||||||
|
|
||||||
x_offset += width;
|
x_offset += width;
|
||||||
widest_line = std::max(widest_line, x_offset);
|
widest_line = std::max(widest_line, x_offset);
|
||||||
|
|
||||||
|
@ -110,7 +113,8 @@ CalculatedLayout TextRunPanel::determine_layout(display::Display *display, displ
|
||||||
// Item fits on the current line
|
// Item fits on the current line
|
||||||
current_line_max_height = std::max(current_line_max_height, height);
|
current_line_max_height = std::max(current_line_max_height, height);
|
||||||
|
|
||||||
auto calculated = std::make_shared<CalculatedTextRun>(run, partial_line, display::Rect(x_offset, y_offset, width, height), baseline, line_number);
|
auto calculated = std::make_shared<CalculatedTextRun>(
|
||||||
|
run, partial_line, display::Rect(x_offset, y_offset, width, height), baseline, line_number);
|
||||||
calculated_layout.runs.push_back(calculated);
|
calculated_layout.runs.push_back(calculated);
|
||||||
|
|
||||||
x_offset += width;
|
x_offset += width;
|
||||||
|
@ -140,9 +144,11 @@ CalculatedLayout TextRunPanel::determine_layout(display::Display *display, displ
|
||||||
|
|
||||||
current_line_max_height = std::max(height, current_line_max_height);
|
current_line_max_height = std::max(height, current_line_max_height);
|
||||||
|
|
||||||
ESP_LOGVV(TAG, "'%s' is remaining after character break checks. Rendering to (%i, %i)", partial_line.c_str(), x_offset, y_offset);
|
ESP_LOGVV(TAG, "'%s' is remaining after character break checks. Rendering to (%i, %i)", partial_line.c_str(),
|
||||||
|
x_offset, y_offset);
|
||||||
|
|
||||||
auto calculated = std::make_shared<CalculatedTextRun>(run, partial_line, display::Rect(x_offset, y_offset, width, height), baseline, line_number);
|
auto calculated = std::make_shared<CalculatedTextRun>(
|
||||||
|
run, partial_line, display::Rect(x_offset, y_offset, width, height), baseline, line_number);
|
||||||
calculated_layout.runs.push_back(calculated);
|
calculated_layout.runs.push_back(calculated);
|
||||||
|
|
||||||
x_offset += width;
|
x_offset += width;
|
||||||
|
@ -162,7 +168,8 @@ CalculatedLayout TextRunPanel::determine_layout(display::Display *display, displ
|
||||||
this->apply_alignment_to_layout(&calculated_layout);
|
this->apply_alignment_to_layout(&calculated_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGV(TAG, "Measured layout is (%i, %i) (%i lines)", calculated_layout.bounds.w, calculated_layout.bounds.h, calculated_layout.line_count);
|
ESP_LOGV(TAG, "Measured layout is (%i, %i) (%i lines)", calculated_layout.bounds.w, calculated_layout.bounds.h,
|
||||||
|
calculated_layout.line_count);
|
||||||
|
|
||||||
return calculated_layout;
|
return calculated_layout;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +203,8 @@ void TextRunPanel::apply_alignment_to_layout(CalculatedLayout *calculated_layout
|
||||||
max_baseline = std::max(run->baseline, max_baseline);
|
max_baseline = std::max(run->baseline, max_baseline);
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGVV(TAG, "Line %i totals (%i, %i) pixels of (%i, %i)", i, total_line_width, max_line_height, calculated_layout->bounds.w, calculated_layout->bounds.h);
|
ESP_LOGVV(TAG, "Line %i totals (%i, %i) pixels of (%i, %i)", i, total_line_width, max_line_height,
|
||||||
|
calculated_layout->bounds.w, calculated_layout->bounds.h)
|
||||||
|
|
||||||
int x_adjustment = 0;
|
int x_adjustment = 0;
|
||||||
int y_adjustment = 0;
|
int y_adjustment = 0;
|
||||||
|
@ -218,7 +226,8 @@ void TextRunPanel::apply_alignment_to_layout(CalculatedLayout *calculated_layout
|
||||||
|
|
||||||
int max_line_y_adjustment = 0;
|
int max_line_y_adjustment = 0;
|
||||||
for (auto run : line_runs) {
|
for (auto run : line_runs) {
|
||||||
ESP_LOGVV(TAG, "Adjusting '%s' from (%i, %i) to (%i, %i)", run->text_.c_str(), run->bounds.x, run->bounds.y, run->bounds.x + x_adjustment, run->bounds.y + y_adjustment);
|
ESP_LOGVV(TAG, "Adjusting '%s' from (%i, %i) to (%i, %i)", run->text_.c_str(), run->bounds.x, run->bounds.y,
|
||||||
|
run->bounds.x + x_adjustment, run->bounds.y + y_adjustment);
|
||||||
run->bounds.x += x_adjustment;
|
run->bounds.x += x_adjustment;
|
||||||
|
|
||||||
switch (y_align) {
|
switch (y_align) {
|
||||||
|
@ -235,7 +244,8 @@ void TextRunPanel::apply_alignment_to_layout(CalculatedLayout *calculated_layout
|
||||||
case display::TextAlign::BASELINE: {
|
case display::TextAlign::BASELINE: {
|
||||||
// Adjust this run based on its difference from the maximum baseline in the line
|
// Adjust this run based on its difference from the maximum baseline in the line
|
||||||
y_adjustment = max_baseline - run->baseline;
|
y_adjustment = max_baseline - run->baseline;
|
||||||
ESP_LOGVV(TAG, "Will adjust '%s' by %i y-pixels (ML: %i, H: %i, BL: %i)", run->text_.c_str(), y_adjustment, max_line_height, run->bounds.h, run->baseline);
|
ESP_LOGVV(TAG, "Will adjust '%s' by %i y-pixels (ML: %i, H: %i, BL: %i)", run->text_.c_str(), y_adjustment,
|
||||||
|
max_line_height, run->bounds.h, run->baseline);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from esphome import automation
|
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.components import font, color
|
from esphome.components import font, color
|
||||||
|
@ -19,6 +18,7 @@ CONF_TEXT_ALIGN = "text_align"
|
||||||
CONF_MAX_WIDTH = "max_width"
|
CONF_MAX_WIDTH = "max_width"
|
||||||
CONF_MIN_WIDTH = "min_width"
|
CONF_MIN_WIDTH = "min_width"
|
||||||
CONF_RUNS = "runs"
|
CONF_RUNS = "runs"
|
||||||
|
CONF_DEBUG_OUTLINE_RUNS = "debug_outline_runs"
|
||||||
|
|
||||||
|
|
||||||
TEXT_ALIGN = {
|
TEXT_ALIGN = {
|
||||||
|
|
Loading…
Reference in a new issue