Skip to content

Commit

Permalink
Merge pull request #28 from bugadani/empty
Browse files Browse the repository at this point in the history
Fix display issue with empty item collections
  • Loading branch information
bugadani authored Aug 23, 2023
2 parents af7627d + 89536e1 commit 9932216
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::marker::PhantomData;

use embedded_graphics::{
pixelcolor::Rgb888,
prelude::{DrawTarget, PixelColor, Point},
prelude::{DrawTarget, PixelColor, Point, Size},
primitives::Rectangle,
};
use embedded_layout::{object_chain::ChainElement, prelude::*, view_group::ViewGroup};
Expand Down Expand Up @@ -84,6 +84,8 @@ where
I: MenuItem<R>,
{
items: C,
/// Used to keep track of the whole collection's position in case it's empty.
position: Point,
_marker: PhantomData<(I, R)>,
}

Expand All @@ -102,6 +104,7 @@ where

Self {
items,
position: Point::zero(),
_marker: PhantomData,
}
}
Expand Down Expand Up @@ -159,6 +162,7 @@ where
I: MenuItem<R>,
{
fn translate_impl(&mut self, by: Point) {
self.position += by;
for view in self.items.as_mut().iter_mut() {
view.translate_impl(by);
}
Expand All @@ -167,7 +171,7 @@ where
fn bounds(&self) -> Rectangle {
let items = &self.items.as_ref();
if items.is_empty() {
return Rectangle::zero();
return Rectangle::new(self.position, Size::zero());
}

let mut rect = items[0].bounds();
Expand Down

0 comments on commit 9932216

Please sign in to comment.