Skip to main content

r/interpreter/graphics/
view.rs

1//! View() data frame viewer using egui_table.
2//!
3//! Sends table data to the GUI thread for rendering in a scrollable
4//! spreadsheet-like window with sticky row names, resizable columns,
5//! and virtual scrolling for large data frames.
6
7// region: TableData
8
9/// Column type for display formatting.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum ColType {
12    Double,
13    Integer,
14    Character,
15    Logical,
16    Other,
17}
18
19impl ColType {
20    pub fn short_name(self) -> &'static str {
21        match self {
22            ColType::Double => "dbl",
23            ColType::Integer => "int",
24            ColType::Character => "chr",
25            ColType::Logical => "lgl",
26            ColType::Other => "???",
27        }
28    }
29
30    pub fn is_numeric(self) -> bool {
31        matches!(self, ColType::Double | ColType::Integer)
32    }
33}
34
35/// Pre-formatted table data for display.
36#[derive(Debug, Clone)]
37pub struct TableData {
38    pub title: String,
39    pub headers: Vec<String>,
40    pub col_types: Vec<ColType>,
41    pub row_names: Vec<String>,
42    /// rows[row][col] — pre-formatted cell strings.
43    pub rows: Vec<Vec<String>>,
44}
45
46// endregion
47
48// region: ViewMessage
49
50/// Message from the REPL thread to the GUI thread for View().
51#[derive(Debug, Clone)]
52pub enum ViewMessage {
53    /// Show a data frame viewer.
54    Show(TableData),
55}
56
57// endregion