Frame

Struct Frame 

Source
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 content
  • Item: the type of the children widgets
  • Coll: 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);

  1. “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>

Source

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.

Source§

impl<Idx: ToOwned<Owned = Idx> + Eq + Hash, Item: Widget, Coll: Index<Idx, Output = Item>> Frame<Idx, Item, Coll>

Source

pub fn find_pos(&self, element_index: &Idx) -> Option<(usize, usize)>

Gives the coordinates of the first occurrence of the element of index element_index in the collection.

Trait Implementations§

Source§

impl<Idx: ToOwned<Owned = Idx>, Item: Widget, Coll: Index<Idx, Output = Item>> Deref for Frame<Idx, Item, Coll>

Source§

type Target = Coll

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<Idx: ToOwned<Owned = Idx>, Item: Widget, Coll: Index<Idx, Output = Item>> DerefMut for Frame<Idx, Item, Coll>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<Idx: ToOwned<Owned = Idx>, Item: Widget, Coll: Index<Idx, Output = Item>> Display for Frame<Idx, Item, Coll>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Idx: ToOwned<Owned = Idx>, Item: Widget, Coll: Index<Idx, Output = Item>> Widget for Frame<Idx, Item, Coll>

Source§

fn displ_line(&self, f: &mut Formatter<'_>, line: usize) -> Result

Prints the given line of the widget. Read more
Source§

fn size(&self) -> (usize, usize)

The current size of the widget, composed of first the width, then the height. Read more

Auto Trait Implementations§

§

impl<Idx, Item, Coll> Freeze for Frame<Idx, Item, Coll>
where Coll: Freeze,

§

impl<Idx, Item, Coll> RefUnwindSafe for Frame<Idx, Item, Coll>
where Coll: RefUnwindSafe, Idx: RefUnwindSafe,

§

impl<Idx, Item, Coll> Send for Frame<Idx, Item, Coll>
where Coll: Send, Idx: Send,

§

impl<Idx, Item, Coll> Sync for Frame<Idx, Item, Coll>
where Coll: Sync, Idx: Sync,

§

impl<Idx, Item, Coll> Unpin for Frame<Idx, Item, Coll>
where Coll: Unpin, Idx: Unpin,

§

impl<Idx, Item, Coll> UnwindSafe for Frame<Idx, Item, Coll>
where Coll: UnwindSafe, Idx: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.