windjammer_ui/components/generated/
advancedcodeeditor.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
6pub struct AdvancedCodeEditor {
7    pub code: String,
8    pub language: String,
9    pub theme: String,
10    pub line_numbers: bool,
11    pub minimap: bool,
12    pub autocomplete: bool,
13}
14
15impl AdvancedCodeEditor {
16    #[inline]
17    pub fn new(code: String) -> AdvancedCodeEditor {
18        AdvancedCodeEditor {
19            code,
20            language: "rust".to_string(),
21            theme: "monokai".to_string(),
22            line_numbers: true,
23            minimap: true,
24            autocomplete: true,
25        }
26    }
27    #[inline]
28    pub fn language(mut self, language: String) -> AdvancedCodeEditor {
29        self.language = language;
30        self
31    }
32    #[inline]
33    pub fn theme(mut self, theme: String) -> AdvancedCodeEditor {
34        self.theme = theme;
35        self
36    }
37    #[inline]
38    pub fn line_numbers(mut self, show: bool) -> AdvancedCodeEditor {
39        self.line_numbers = show;
40        self
41    }
42    #[inline]
43    pub fn minimap(mut self, show: bool) -> AdvancedCodeEditor {
44        self.minimap = show;
45        self
46    }
47    #[inline]
48    pub fn autocomplete(mut self, enable: bool) -> AdvancedCodeEditor {
49        self.autocomplete = enable;
50        self
51    }
52}
53
54impl Renderable for AdvancedCodeEditor {
55    #[inline]
56    fn render(self) -> String {
57        let features_class = {
58            if self.minimap {
59                " wj-editor-with-minimap".to_string()
60            } else {
61                "".to_string()
62            }
63        };
64        let line_class = {
65            if self.line_numbers {
66                " wj-editor-with-lines".to_string()
67            } else {
68                "".to_string()
69            }
70        };
71        format!(
72            "<div class='wj-advanced-editor wj-editor-{} wj-editor-theme-{}{}{}'>
73  <div class='wj-editor-toolbar'>
74    <span>Language: {}</span>
75    <span>Theme: {}</span>
76  </div>
77  <div class='wj-editor-main'>
78    <textarea class='wj-editor-textarea'>
79{}</textarea>
80    {}
81  </div>
82</div>",
83            self.language,
84            self.theme,
85            features_class,
86            line_class,
87            self.language,
88            self.theme,
89            self.code,
90            {
91                if self.minimap {
92                    "<div class='wj-editor-minimap'></div>".to_string()
93                } else {
94                    "".to_string()
95                }
96            }
97        )
98    }
99}