1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use embedded_graphics::{prelude::Point, primitives::Rectangle};
use crate::{prelude::RectExt, View};
mod object_chain;
mod views;
pub use views::Views;
pub trait ViewGroup: View {
fn len(&self) -> usize;
fn at(&self, idx: usize) -> &dyn View;
fn at_mut(&mut self, idx: usize) -> &mut dyn View;
}
pub struct ViewGroupHelper;
impl ViewGroupHelper {
pub fn translate(vg: &mut impl ViewGroup, by: Point) {
for i in 0..ViewGroup::len(vg) {
vg.at_mut(i).translate_impl(by);
}
}
pub fn bounds(vg: &impl ViewGroup) -> Rectangle {
let mut rect = vg.at(0).bounds();
for i in 1..vg.len() {
rect = rect.enveloping(&vg.at(i).bounds());
}
rect
}
}