Skip to main content

wedi_widget/layout/
screen.rs

1/// 螢幕佈局資訊
2///
3/// 管理編輯器視窗的尺寸和滾動位置。
4///
5/// # 範例
6///
7/// ```rust
8/// use wedi_widget::ScreenLayout;
9///
10/// let mut layout = ScreenLayout::new(24, 80);
11/// layout.scroll_to(10, 0); // 滾動到第 10 行
12/// layout.resize(30, 100);  // 調整尺寸
13/// ```
14#[derive(Debug, Clone, Copy)]
15pub struct ScreenLayout {
16    /// 視窗頂部顯示的邏輯行號
17    pub offset_row: usize,
18    /// 水平偏移(單行模式使用)
19    pub offset_col: usize,
20    /// 螢幕行數
21    pub screen_rows: usize,
22    /// 螢幕列數
23    pub screen_cols: usize,
24}
25
26impl ScreenLayout {
27    /// 建立新的螢幕佈局
28    ///
29    /// # Arguments
30    /// * `rows` - 螢幕行數
31    /// * `cols` - 螢幕列數
32    pub fn new(rows: usize, cols: usize) -> Self {
33        Self {
34            offset_row: 0,
35            offset_col: 0,
36            screen_rows: rows,
37            screen_cols: cols,
38        }
39    }
40
41    /// 調整螢幕尺寸
42    ///
43    /// # Arguments
44    /// * `rows` - 新的螢幕行數
45    /// * `cols` - 新的螢幕列數
46    pub fn resize(&mut self, rows: usize, cols: usize) {
47        self.screen_rows = rows;
48        self.screen_cols = cols;
49    }
50
51    /// 滾動到指定位置
52    ///
53    /// # Arguments
54    /// * `row` - 目標行號
55    /// * `col` - 目標列號
56    pub fn scroll_to(&mut self, row: usize, col: usize) {
57        self.offset_row = row;
58        self.offset_col = col;
59    }
60}