Skip to main content

handmade/text/
line.rs

1use std::rc::Rc;
2
3use super::{Word, PageProps, ImagesMap};
4
5pub struct Line<'a> {
6    pub words: Vec<Word<'a>>,
7    pub width: f32,
8    spaces_counter: i32,
9    page_props: &'a PageProps<'a>,
10    imgs_map: Rc<ImagesMap<'a>>
11}
12
13impl<'a> Line<'a> {
14    pub fn new(page_props : &'a PageProps<'a>, imgs_map : Rc<ImagesMap<'a>>) -> Line<'a> {
15        Line {
16            words: Vec::new(),
17            width: 0.0,
18            spaces_counter: 0,
19            page_props,
20            imgs_map
21        }
22    }
23
24    pub fn push(&mut self, word : Word<'a>) {
25        if self.width != 0.0 {
26            self.spaces_counter += 1;
27            self.width += word.page_props.space_width;
28        }
29        self.width += word.width;
30        self.words.push(word);
31    }
32}