terminal make_label() helper

This commit is contained in:
Michael Sippel 2021-06-12 04:15:56 +02:00
parent 9d91f938b1
commit 44cba54320
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -22,3 +22,24 @@ pub trait TerminalView = GridView<Item = TerminalAtom>;
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
use {
crate::{
sequence::VecBuffer,
core::{ViewPort, OuterViewPort}
},
cgmath::Point2
};
pub fn make_label(s: &str) -> OuterViewPort<dyn TerminalView> {
let label_port = ViewPort::new();
let label = VecBuffer::with_data(s.chars().collect(), label_port.inner());
label_port.outer()
.to_sequence()
.map(|c| TerminalAtom::from(c))
.to_index()
.map_key(
|idx| Point2::new(*idx as i16, 0),
|pt| if pt.y == 0 { Some(pt.x as usize) } else { None }
)
}