From ee77485a2daeab60b2f2a99376d293ea679dc547 Mon Sep 17 00:00:00 2001 From: Michael Davidson Date: Sat, 6 Jan 2024 12:01:03 +1100 Subject: [PATCH] Apply clang-tidy fixes --- .../graphical_layout/text_run_panel.cpp | 21 +++++++++---------- .../graphical_layout/text_run_panel.h | 10 ++++----- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/esphome/components/graphical_layout/text_run_panel.cpp b/esphome/components/graphical_layout/text_run_panel.cpp index dd5b1f653f..5dcb93f2fb 100644 --- a/esphome/components/graphical_layout/text_run_panel.cpp +++ b/esphome/components/graphical_layout/text_run_panel.cpp @@ -36,14 +36,14 @@ void TextRunPanel::setup_complete() { 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); + this->determine_layout_(display, display::Rect(0, 0, this->max_width_, display->get_height()), true); return calculated.bounds; } void TextRunPanel::render_internal(display::Display *display, display::Rect bounds) { ESP_LOGD(TAG, "Rendering to (%i, %i)", bounds.w, bounds.h); - CalculatedLayout layout = this->determine_layout(display, bounds, true); + CalculatedLayout layout = this->determine_layout_(display, bounds, true); for (const auto &calculated : layout.runs) { if (calculated->run->background_color_ != display::COLOR_OFF) { @@ -62,7 +62,7 @@ void TextRunPanel::render_internal(display::Display *display, display::Rect boun } } -std::vector> TextRunPanel::split_runs_into_words() { +std::vector> TextRunPanel::split_runs_into_words_() { std::vector> runs; for (TextRunBase *run : this->text_runs_) { @@ -94,7 +94,7 @@ std::vector> TextRunPanel::split_runs_into_wo return runs; } -std::vector> TextRunPanel::fit_words_to_bounds( +std::vector> TextRunPanel::fit_words_to_bounds_( const std::vector> &runs, display::Rect bounds) { int x_offset = 0; int y_offset = 0; @@ -104,8 +104,7 @@ std::vector> TextRunPanel::fit_words_to_bounds( auto current_line = std::make_shared(current_line_number); lines.push_back(current_line); - for (int i = 0; i < runs.size(); i++) { - const auto &run = runs.at(i); + for (const auto &run : runs) { if (run->bounds.w + x_offset > bounds.w) { // Overflows the current line create a new line x_offset = 0; @@ -129,7 +128,7 @@ std::vector> TextRunPanel::fit_words_to_bounds( return lines; } -void TextRunPanel::apply_alignment_to_lines(std::vector> &lines, +void TextRunPanel::apply_alignment_to_lines_(std::vector> &lines, display::TextAlign alignment) { const auto x_align = display::TextAlign(int(this->text_align_) & TEXT_ALIGN_X_MASK); const auto y_align = display::TextAlign(int(this->text_align_) & TEXT_ALIGN_Y_MASK); @@ -193,10 +192,10 @@ void TextRunPanel::apply_alignment_to_lines(std::vector> runs = this->split_runs_into_words(); - std::vector> lines = this->fit_words_to_bounds(runs, bounds); - this->apply_alignment_to_lines(lines, this->text_align_); +CalculatedLayout TextRunPanel::determine_layout_(display::Display *display, display::Rect bounds, bool apply_alignment) { + std::vector> runs = this->split_runs_into_words_(); + std::vector> lines = this->fit_words_to_bounds_(runs, bounds); + this->apply_alignment_to_lines_(lines, this->text_align_); CalculatedLayout layout; layout.runs = runs; diff --git a/esphome/components/graphical_layout/text_run_panel.h b/esphome/components/graphical_layout/text_run_panel.h index 525225b92a..d421b2e4b9 100644 --- a/esphome/components/graphical_layout/text_run_panel.h +++ b/esphome/components/graphical_layout/text_run_panel.h @@ -131,7 +131,7 @@ class LineInfo { public: LineInfo(int line_number) { this->line_number = line_number; } - void add_run(std::shared_ptr run) { + void add_run(const std::shared_ptr &run) { this->total_width += run->bounds.w; this->max_height = std::max(this->max_height, run->bounds.h); this->max_baseline = std::max(this->max_baseline, run->baseline); @@ -166,11 +166,11 @@ class TextRunPanel : public LayoutItem { void set_debug_outline_runs(bool debug_outline_runs) { this->debug_outline_runs_ = debug_outline_runs; }; protected: - CalculatedLayout determine_layout(display::Display *display, display::Rect bounds, bool apply_alignment); - std::vector> split_runs_into_words(); - std::vector> fit_words_to_bounds( + CalculatedLayout determine_layout_(display::Display *display, display::Rect bounds, bool apply_alignment); + std::vector> split_runs_into_words_(); + std::vector> fit_words_to_bounds_( const std::vector> &runs, display::Rect bounds); - void apply_alignment_to_lines(std::vector> &lines, display::TextAlign alignment); + void apply_alignment_to_lines_(std::vector> &lines, display::TextAlign alignment); std::vector text_runs_; display::TextAlign text_align_{display::TextAlign::TOP_LEFT};