third_party/rust/lalrpop/src/message/text.rs
author Dorel Luca <dluca@mozilla.com>
Sat, 12 Jan 2019 03:43:46 +0200
changeset 453620 def9811f0311
parent 453619 3c4b8e03e722
child 460816 c5e856d5edba
permissions -rw-r--r--
Backed out 2 changesets (bug 1516337) for build bustage. CLOSED TREE Backed out changeset 3c4b8e03e722 (bug 1516337) Backed out changeset 4fc377013db5 (bug 1516337)

use ascii_canvas::AsciiView;
use style::Style;

use super::*;

/// Text to be display. This will be flowed appropriately depending on
/// the container; e.g., in a Horiz, it will be one unit, but in a
/// Wrap, it will be broken up word by word.
#[derive(Debug)]
pub struct Text {
    text: String,
}

impl Text {
    pub fn new(text: String) -> Self {
        Text { text: text }
    }
}

impl Content for Text {
    fn min_width(&self) -> usize {
        self.text.chars().count()
    }

    fn emit(&self, view: &mut AsciiView) {
        view.write_chars(0, 0, self.text.chars(), Style::new())
    }

    fn into_wrap_items(self: Box<Self>, wrap_items: &mut Vec<Box<Content>>) {
        wrap_items.extend(
            self.text
                .split_whitespace()
                .map(|word| Text::new(word.to_string()))
                .map(|item| Box::new(item) as Box<Content>),
        );
    }
}