windjammer_ui/components/generated/
filetree.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use std::fmt::Write;
4
5use super::traits::Renderable;
6
7#[derive(Debug, Clone, Default)]
8pub struct FileNode {
9    pub name: String,
10    pub is_directory: bool,
11    pub children: Vec<FileNode>,
12    pub expanded: bool,
13}
14
15impl FileNode {
16    #[inline]
17    pub fn new(name: String, is_directory: bool) -> FileNode {
18        FileNode {
19            name,
20            is_directory,
21            children: Vec::new(),
22            expanded: false,
23        }
24    }
25    #[inline]
26    pub fn child(mut self, node: FileNode) -> FileNode {
27        self.children.push(node);
28        self
29    }
30    #[inline]
31    pub fn expanded(mut self, expanded: bool) -> FileNode {
32        self.expanded = expanded;
33        self
34    }
35    #[inline]
36    pub fn render(&self, depth: i32) -> String {
37        let indent = "  ".repeat(depth as usize);
38        let icon = {
39            if self.is_directory {
40                if self.expanded {
41                    "📂".to_string()
42                } else {
43                    "📁".to_string()
44                }
45            } else {
46                "📄".to_string()
47            }
48        };
49        let mut html = {
50            let mut __s = String::with_capacity(64);
51            write!(
52                &mut __s,
53                "{}{} {}
54",
55                indent, icon, self.name
56            )
57            .unwrap();
58            __s
59        };
60        if self.is_directory && self.expanded {
61            let mut i = 0;
62            while i < (self.children.len() as i64) {
63                let child = &self.children[i as usize];
64                html = format!("{}{}", html, child.render(depth + 1));
65                i += 1;
66            }
67        }
68        html
69    }
70}
71
72#[derive(Debug, Clone)]
73pub struct FileTree {
74    pub root: FileNode,
75}
76
77impl FileTree {
78    #[inline]
79    pub fn new(root: FileNode) -> FileTree {
80        FileTree { root }
81    }
82}
83
84impl Renderable for FileTree {
85    #[inline]
86    fn render(self) -> String {
87        format!(
88            "<div class='wj-file-tree'>
89{}</div>",
90            self.root.render(0)
91        )
92    }
93}