<commit_before>use std::cmp::max;

use vec::Vec2;
use view::{View,SizeRequest,DimensionRequest};
use event::EventResult;
use printer::Printer;

/// Simple stack of views.
/// Only the top-most view is active and can receive input.
pub struct StackView {
    layers: Vec<Layer>,
}

struct Layer {
    view: Box<View>,
    size: Vec2,
}

impl StackView {
    /// Creates a new empty StackView
    pub fn new() -> Self {
        StackView {
            layers: Vec::new(),
        }
    }

    /// Add new view on top of the stack.
    pub fn add_layer<T: 'static + View>(&mut self, view: T) {
        self.layers.push(Layer {
            view: Box::new(view),
            size: Vec2::new(0,0),
        });
    }

    /// Remove the top-most layer.
    pub fn pop_layer(&mut self) {
        self.layers.pop();
    }
}


impl View for StackView {
    fn draw(&self, printer: &Printer) {
        match self.layers.last() {
            None => (),
            Some(v) => {
                let offset = (printer.size - v.size) / 2;
                v.view.draw(&printer.sub_printer(offset, v.size));
            },
        }
    }

    fn on_key_event(&mut self, ch: i32) -> EventResult {
        match self.layers.last_mut() {
            None => EventResult::Ignored,
            Some(v) => v.view.on_key_event(ch),
        }
    }

    fn layout(&mut self, size: Vec2) {
        let req = SizeRequest {
            w: DimensionRequest::AtMost(size.x),
            h: DimensionRequest::AtMost(size.y),<commit_msg>Fix stack_view when screen is smaller than content<commit_after>use std::cmp::max;

use vec::Vec2;
use view::{View,SizeRequest,DimensionRequest};
use event::EventResult;
use printer::Printer;

/// Simple stack of views.
/// Only the top-most view is active and can receive input.
pub struct StackView {
    layers: Vec<Layer>,
}

struct Layer {
    view: Box<View>,
    size: Vec2,
}

impl StackView {
    /// Creates a new empty StackView
    pub fn new() -> Self {
        StackView {
            layers: Vec::new(),
        }
    }

    /// Add new view on top of the stack.
    pub fn add_layer<T: 'static + View>(&mut self, view: T) {
        self.layers.push(Layer {
            view: Box::new(view),
            size: Vec2::new(0,0),
        });
    }

    /// Remove the top-most layer.
    pub fn pop_layer(&mut self) {
        self.layers.pop();
    }
}


impl View for StackView {
    fn draw(&self, printer: &Printer) {
        match self.layers.last() {
            None => (),
            Some(v) => {
                // Center the view
                let view_size = Vec2::min(printer.size, v.size);
                let offset = (printer.size - view_size) / 2;
                v.view.draw(&printer.sub_printer(offset, v.size));
            },
        }
    }

    fn on_key_event(&mut self, ch: i32) -> EventResult {
        match self.layers.last_mut() {
            None => EventResult::Ignored,
            Some(v) => v.view.on_key_event(ch),
        }
    }

    fn layout(&mut self, size: Vec2) {
        let req = SizeRequest {
            w: DimensionRequest::AtMost(size.x),
            h: DimensionRequest::AtMost(size.y),
{'fraction_non_alphanumeric': 0.1388712745719721, 'fraction_numerical': 0.006024096385542169, 'mean_word_length': 1.8891941391941391, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5683808', 'n_tokens_mistral': 1015, 'n_tokens_neox': 994, 'n_words': 257}