pub struct FixedWidth<E> { /* private fields */ }Expand description
An element that pads or truncates its contents to a constant width.
Implementations§
Source§impl<E> FixedWidth<E>
impl<E> FixedWidth<E>
Sourcepub fn new(width: usize, content: E) -> Self
pub fn new(width: usize, content: E) -> Self
Creates a new FixedWidth with the specified width and content.
Sourcepub fn truncated(self, truncate: Direction) -> Self
pub fn truncated(self, truncate: Direction) -> Self
Changes the side on which the content is truncated.
This option only takes effect if the content is wider than the width.
Examples found in repository?
examples/input.rs (line 24)
11fn main() -> std::io::Result<()> {
12 let stdout = std::io::stdout().into_raw_mode()?;
13 let mut r = Renderer::new(stdout);
14
15 let mut name = String::new();
16
17 let mut events = std::io::stdin().events();
18 loop {
19 r.clear()?;
20 r.render((
21 "Enter your name: ".into_element(),
22 (name.into_element(), Cursor, Gap(1))
23 .fixed_width(20)
24 .truncated(Direction::Left)
25 .with_style(Style::bg(240)),
26 ))?;
27 r.finish()?;
28
29 let Some(event) = events.next().transpose()? else {
30 break;
31 };
32 match event {
33 Event::Key(Key::Char(ch)) if !ch.is_ascii_control() => name.push(ch),
34 Event::Key(Key::Char('\n' | '\r')) => break,
35 Event::Key(Key::Backspace) => {
36 name.pop();
37 }
38 _ => {}
39 }
40 }
41
42 r.clear()?;
43 drop(r);
44 println!("Your name is {name:?}");
45 Ok(())
46}Trait Implementations§
Source§impl<E: Clone> Clone for FixedWidth<E>
impl<E: Clone> Clone for FixedWidth<E>
Source§fn clone(&self) -> FixedWidth<E>
fn clone(&self) -> FixedWidth<E>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<E: Debug> Debug for FixedWidth<E>
impl<E: Debug> Debug for FixedWidth<E>
Auto Trait Implementations§
impl<E> Freeze for FixedWidth<E>where
E: Freeze,
impl<E> RefUnwindSafe for FixedWidth<E>where
E: RefUnwindSafe,
impl<E> Send for FixedWidth<E>where
E: Send,
impl<E> Sync for FixedWidth<E>where
E: Sync,
impl<E> Unpin for FixedWidth<E>where
E: Unpin,
impl<E> UnwindSafe for FixedWidth<E>where
E: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<E> IntoElement for Ewhere
E: Element,
impl<E> IntoElement for Ewhere
E: Element,
Source§type ElementType = E
type ElementType = E
The element type to be converted into.
Source§fn into_element(self) -> <E as IntoElement>::ElementType
fn into_element(self) -> <E as IntoElement>::ElementType
Converts this type into an
Element.Source§fn fixed_width(self, width: usize) -> FixedWidth<Self::ElementType>
fn fixed_width(self, width: usize) -> FixedWidth<Self::ElementType>
Convenience function to wrap this element in a
FixedWidth.Source§fn with_style(self, style: Style) -> Styled<Self::ElementType>
fn with_style(self, style: Style) -> Styled<Self::ElementType>
Convenience function to wrap this element in a
Styled.