From 29d4984b3377137e35a99e25909aa1bbd3407dd4 Mon Sep 17 00:00:00 2001 From: Michael Davidson Date: Sat, 20 Jan 2024 16:42:54 +1100 Subject: [PATCH] When fixed_dimension_panel uses the display width/height ensure it only uses the available remaining width/height based on where it's positioned --- .../components/graphical_layout/fixed_dimension_panel.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/esphome/components/graphical_layout/fixed_dimension_panel.cpp b/esphome/components/graphical_layout/fixed_dimension_panel.cpp index 20d92ac4ee..1910f4cd5e 100644 --- a/esphome/components/graphical_layout/fixed_dimension_panel.cpp +++ b/esphome/components/graphical_layout/fixed_dimension_panel.cpp @@ -32,12 +32,15 @@ display::Rect FixedDimensionPanel::measure_item_internal(display::Display *displ // Call measure_child so they can do any measurements display::Rect child_size = this->child_->measure_item(display); display::Rect rect(0, 0, this->width_.value(), this->height_.value()); + display::Point origin_in_global = display->get_local_coordinates(); if (rect.w < 0) { if (this->unset_width_uses_display_width_) { rect.w = display->get_width(); // We need to account for our own padding + margin + border rect.w -= this->margin_.horizontal() + this->border_.horizontal() + this->padding_.horizontal(); + // Account for where we sit within the display + rect.w -= origin_in_global.x; } else { rect.w = child_size.w; } @@ -48,6 +51,8 @@ display::Rect FixedDimensionPanel::measure_item_internal(display::Display *displ rect.h = display->get_height(); // We need to account for our own padding + margin + border rect.h -= this->margin_.vertical() + this->border_.vertical() + this->padding_.vertical(); + // Account for where we sit within the display + rect.h -= origin_in_global.y; } else { rect.h = child_size.h; }