windjammer_ui/components/generated/
messagelist.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Debug, Clone, Default)]
6pub struct MessageList {
7    pub messages: Vec<String>,
8    pub height: String,
9    pub auto_scroll: bool,
10}
11
12impl MessageList {
13    #[inline]
14    pub fn new() -> MessageList {
15        MessageList {
16            messages: Vec::new(),
17            height: String::from("600px"),
18            auto_scroll: true,
19        }
20    }
21    #[inline]
22    pub fn message(mut self, message: String) -> MessageList {
23        self.messages.push(message);
24        self
25    }
26    #[inline]
27    pub fn height(mut self, height: String) -> MessageList {
28        self.height = height;
29        self
30    }
31    #[inline]
32    pub fn auto_scroll(mut self, auto_scroll: bool) -> MessageList {
33        self.auto_scroll = auto_scroll;
34        self
35    }
36}
37
38impl Renderable for MessageList {
39    #[inline]
40    fn render(self) -> String {
41        let scroll_script = {
42            if self.auto_scroll {
43                "onload='this.scrollTop = this.scrollHeight'".to_string()
44            } else {
45                "".to_string()
46            }
47        };
48        format!(
49            "<div class='wj-message-list' style='height: {}' {}>
50                {}
51            </div>",
52            self.height,
53            scroll_script,
54            self.messages.join("")
55        )
56    }
57}