third_party/rust/lalrpop/src/message/vert.rs
author Bastien Orivel <eijebong@bananium.fr>
Sat, 12 Jan 2019 03:19:31 +0200
changeset 453619 3c4b8e03e7221c6edc8651a13cd84cc344ce9b76
parent 412088 a97cccaa866a0fbd5721842ad8d8e862cd26ea65
child 453620 def9811f03111c1fe26bb578255cc30e56a87414
permissions -rw-r--r--
Bug 1516337 - Part 2: Revendor rust dependencies r=froydnj

use super::*;
use ascii_canvas::AsciiView;

#[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;
    }
}