From 44cba54320c6b1727425ca680ae7992e7cc776e4 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sat, 12 Jun 2021 04:15:56 +0200 Subject: [PATCH] terminal make_label() helper --- nested/src/terminal/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/nested/src/terminal/mod.rs b/nested/src/terminal/mod.rs index 65d8f8a..587a9f2 100644 --- a/nested/src/terminal/mod.rs +++ b/nested/src/terminal/mod.rs @@ -22,3 +22,24 @@ pub trait TerminalView = GridView; //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> +use { + crate::{ + sequence::VecBuffer, + core::{ViewPort, OuterViewPort} + }, + cgmath::Point2 +}; + +pub fn make_label(s: &str) -> OuterViewPort { + 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 } + ) +} +