wedi_widget/config.rs
1/// 編輯器配置選項
2///
3/// 用於自訂編輯器的顯示和行為設定。
4///
5/// # 範例
6///
7/// ```rust
8/// use wedi_widget::EditorConfig;
9///
10/// let config = EditorConfig::new()
11/// .with_line_numbers(true)
12/// .with_wrap_mode(true)
13/// .with_tab_width(4)
14/// .with_theme("base16-ocean.dark".to_string());
15/// ```
16#[derive(Debug, Clone)]
17pub struct EditorConfig {
18 /// 是否顯示行號
19 pub show_line_numbers: bool,
20 /// 是否啟用自動換行(true=多行換行, false=單行水平滾動)
21 pub wrap_mode: bool,
22 /// Tab 鍵寬度(空格數)
23 pub tab_width: usize,
24 /// 語法高亮主題名稱
25 pub theme: String,
26}
27
28impl Default for EditorConfig {
29 fn default() -> Self {
30 Self {
31 show_line_numbers: true,
32 wrap_mode: true,
33 tab_width: 4,
34 theme: "base16-ocean.dark".into(),
35 }
36 }
37}
38
39impl EditorConfig {
40 /// 建立預設配置
41 pub fn new() -> Self {
42 Self::default()
43 }
44
45 /// 設定是否顯示行號
46 ///
47 /// # Arguments
48 /// * `show` - true 為顯示,false 為隱藏
49 pub fn with_line_numbers(mut self, show: bool) -> Self {
50 self.show_line_numbers = show;
51 self
52 }
53
54 /// 設定是否啟用自動換行
55 ///
56 /// # Arguments
57 /// * `wrap` - true 為多行換行模式,false 為單行水平滾動模式
58 pub fn with_wrap_mode(mut self, wrap: bool) -> Self {
59 self.wrap_mode = wrap;
60 self
61 }
62
63 /// 設定 Tab 鍵寬度
64 ///
65 /// # Arguments
66 /// * `width` - Tab 鍵對應的空格數
67 pub fn with_tab_width(mut self, width: usize) -> Self {
68 self.tab_width = width;
69 self
70 }
71
72 /// 設定語法高亮主題
73 ///
74 /// # Arguments
75 /// * `theme` - 主題名稱(例如 "base16-ocean.dark")
76 pub fn with_theme(mut self, theme: String) -> Self {
77 self.theme = theme;
78 self
79 }
80}