pub struct Frame<Idx: ToOwned<Owned = Idx>, Item: Widget, Coll: Index<Idx, Output = Item>> { /* private fields */ }
Expand description
A Frame1 is a widget containing a collection of widgets that it is able to display.
The contained collection of widgets can be of any type, as long as it is indexable and that the indexes to access the widgets that the frame needs to be displayed are given. The contained widgets’ size are assumed to never change, and each line is assumed to be of the same length.
Once a collection is framed, it can actually still be used as the original collection since
frames implements Deref
and DerefMut
.
The generics arguments of Frame are:
Idx
: the type of the indexes to access the collection’s contentItem
: the type of the children widgetsColl
: the type of the wrapped collection
Building a frame itself might not seem straightforward, so the frame macro is given to help building it. Check it’s documentation for more details.
use terminity_widgets::frame;
use terminity_widgets::widgets::text::Text;
use terminity_widgets::widgets::frame::Frame;
let texts = vec![
Text::new(["Hello".into(), "-----".into()], 5),
Text::new(["World".into(), "".into()], 5),
];
// Generics not needed here, but written for an example of how they work
let mut framed_texts: Frame<usize, Text<2>, Vec<_>> = frame!(
texts => { 'H': 0, 'W': 1 }
"*~~~~~~~~~~~~~~*"
"| HHHHH WWWWW! |"
"| HHHHH-WWWWW- |"
"*~~~~~~~~~~~~~~*"
);
framed_texts[1][1] = String::from("-----");
println!("{}", framed_texts);
“Frame” may be referred as “Collection Frame” (but still named
Frame
in code) when “Structure Frames” will be a thing. A structure frame will be implemented through a trait and a macro, allowing more flexibility in the types of the frame’s children. ↩
Implementations§
Source§impl<Idx: ToOwned<Owned = Idx> + Eq + Hash + Clone, Item: Widget, Coll: Index<Idx, Output = Item>> Frame<Idx, Item, Coll>
impl<Idx: ToOwned<Owned = Idx> + Eq + Hash + Clone, Item: Widget, Coll: Index<Idx, Output = Item>> Frame<Idx, Item, Coll>
Sourcepub fn new(
content: Vec<(String, Vec<((Idx, usize), String)>)>,
widgets: Coll,
) -> Self
pub fn new( content: Vec<(String, Vec<((Idx, usize), String)>)>, widgets: Coll, ) -> Self
Creates a frame out of the given widgets. Finds the frame’s size using the first line.
The content of a line is described as a prefix followed by a (maybe empty) list of tuples
containing data to display the appropriate widget’s line and a suffix to this widget’s line.
The data data to display the appropriate widget’s line is simply the widget’s index and the
index of the widget’s line to display. For instance, a line of the form "| aa | bb |"
where aa
is the line n°0 of the widget of index 'a'
and bb
is the line n°1 of the
widget of index 'b'
, the line will be of the form
("| ", [(('a', 0), " | "), (('b', 1), " |")])
.
If this function seems too complicated to use, consider using the frame!
macro, that actually just compiles to an assignation and a Frame::new
invocation.