third_party/rust/lalrpop/src/message/vert.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 super::*;

#[derive(Debug)]
pub struct Vert {
    items: Vec<Box<Content>>,
    separate: usize, // 0 => overlapping, 1 => each on its own line, 2 => paragraphs
}

impl Vert {
    pub fn new(items: Vec<Box<Content>>, separate: usize) -> Self {
        Vert {
            items: items,
            separate: separate,
        }
    }
}

impl Content for Vert {
    fn min_width(&self) -> usize {
        self.items.iter().map(|c| c.min_width()).max().unwrap()
    }

    fn emit(&self, view: &mut AsciiView) {
        emit_vert(view, &self.items, self.separate);
    }

    fn into_wrap_items(self: Box<Self>, wrap_items: &mut Vec<Box<Content>>) {
        wrap_items.push(self);
    }
}

pub fn emit_vert(view: &mut AsciiView, items: &[Box<Content>], separate: usize) {
    let mut row = 0;
    for item in items {
        let (end_row, _) = item.emit_at(view, row, 0);
        row = end_row + separate;
    }
}