embedded_layout/layout/
mod.rs

1//! Layouts - arrange multiple views
2//!
3//! A layout is a piece of code that arranges views on the display according to rules of the
4//! particular layout algorithm.
5//!
6//! # Implementing layouts
7//!
8//! In embedded-layout, layout objects aren't special in any way. There is no `Layout` trait to
9//! implement, no required API to provide. Instead, as a developer, you may decide how to make your
10//! layout as comfortable as possible.
11//!
12//! A layout works on a group of [`View`] objects, in the form of a [`ViewGroup`]. The `ViewGroup`
13//! provides an interface to access view objects of any type.
14//!
15//! As an example, a (admittedly not very useful) layout that aligns all views in a `ViewGroup` to
16//! the `(0, 0)` point, would look something like this:
17//!
18//! ```rust
19//! # use embedded_layout::prelude::*;
20//! use embedded_layout::view_group::ViewGroup;
21//!
22//! struct MyLayout;
23//!
24//! impl MyLayout {
25//!    pub fn arrange(view_group: &mut impl ViewGroup) {
26//!        for idx in 0..view_group.len() {
27//!            let view = view_group.at_mut(idx);
28//!            let by = -view.bounds().top_left;
29//!            // Because `ViewGroup` returns a `&[mut] dyn View`, we need to call the object-safe
30//!            // version of `translate`.
31//!            view.translate_impl(by);
32//!        }
33//!    }
34//! }
35//! ```
36//!
37//! As you can see, you can choose not to take ownership of the `ViewGroup`. If you do, make sure
38//! you also implement `View` and `Drawable` (you probably don't want to implement `ViewGroup`) for
39//! your layout object and you provide a way to retrieve the original `ViewGroup` object!
40//!
41//! For a more (but not really) complex example, you may check the source of [`LinearLayout`].
42//!
43//! [`View`]: crate::View
44//! [`ViewGroup`]: crate::view_group::ViewGroup
45//! [`LinearLayout`]: crate::layout::linear::LinearLayout
46
47pub mod linear;