tech_ui/
tabs.rs

1use super::{
2    classed,
3    HtmlProducer,Block,
4};
5
6pub struct Tabs {
7    tabs: Vec<Tab>,
8}
9pub struct Tab {
10    pub name: String,
11    pub count: usize,
12    pub active: bool,
13    pub href: String,
14}
15impl Tabs {
16    pub fn new(_producer: &mut HtmlProducer, tabs: Vec<Tab>) -> Tabs {
17        Tabs{ tabs: tabs }
18    }
19    pub fn set_active(&mut self, name: &str) {
20        for tab in &mut self.tabs {
21            if tab.name == name {
22                tab.active = true;
23            }
24        }
25    }
26    /*fn push(mut self, tab: Tab) -> Tabs {
27        self.tabs.push(tab);
28        self
29    }*/
30    pub fn blocks(&self) -> Block {
31        let mut bl = Block::new("tab_row");
32        for tab in &self.tabs {
33            let act = match tab.active {
34                true => "tab_button_active",
35                false => "tab_button",
36            };        
37            bl = bl.sub({
38                let mut bl = Block::new(act).text({
39                    let mut t = tab.name.clone();
40                    match !tab.active && (tab.count > 0) {
41                        true => { t += &classed("tab_count",tab.count); },
42                        false => { t += &classed("tab_count_empty","&nbsp;"); },
43                    }
44                    t
45                });
46                if !tab.active {
47                    bl = bl.onclick(format!("tabClicked(\"{}\");",tab.href));
48                }
49                bl
50            });
51        }
52        bl = bl.sub(Block::new("tab_finish").text("<img width=1 height=1>"));
53        Block::new("tabs").sub(bl)
54    }
55}