• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ergrelet / resym / 4590214962

pending completion
4590214962

push

github

ergrelet
Move main UI components' update logic into their own files

281 of 281 new or added lines in 6 files covered. (100.0%)

781 of 2180 relevant lines covered (35.83%)

0.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/resym/src/ui_components/code_view.rs
1
use eframe::egui;
2
use resym_core::syntax_highlighting::CodeTheme;
3

4
use crate::{mode::ResymAppMode, settings::ResymAppSettings, syntax_highlighting::highlight_code};
5

6
pub struct CodeViewComponent {}
7

8
impl CodeViewComponent {
9
    pub fn new() -> Self {
×
10
        Self {}
11
    }
12

13
    pub fn update(
×
14
        &mut self,
15
        app_settings: &ResymAppSettings,
16
        current_mode: &ResymAppMode,
17
        ui: &mut egui::Ui,
18
    ) {
19
        const LANGUAGE_SYNTAX: &str = "cpp";
20
        let theme = if app_settings.use_light_theme {
×
21
            CodeTheme::light(app_settings.font_size, LANGUAGE_SYNTAX.to_string())
×
22
        } else {
23
            CodeTheme::dark(app_settings.font_size, LANGUAGE_SYNTAX.to_string())
×
24
        };
25

26
        let line_desc = if let ResymAppMode::Comparing(_, _, _, line_changes, _) = current_mode {
×
27
            Some(line_changes)
×
28
        } else {
29
            None
×
30
        };
31

32
        // Layouter that'll disable wrapping and apply syntax highlighting if needed
33
        let mut layouter = |ui: &egui::Ui, string: &str, _wrap_width: f32| {
×
34
            let layout_job = highlight_code(
35
                ui.ctx(),
×
36
                &theme,
×
37
                string,
×
38
                app_settings.enable_syntax_hightlighting,
×
39
                line_desc,
×
40
            );
41
            ui.fonts(|fonts| fonts.layout_job(layout_job))
×
42
        };
43

44
        // Type dump area
45
        egui::ScrollArea::both()
×
46
            .auto_shrink([false, false])
×
47
            .show(ui, |ui| {
×
48
                // TODO(ergrelet): see if there's a better way to compute this width.
49
                let line_number_digit_width = 2 + app_settings.font_size as u32;
×
50
                let (num_colums, min_column_width) = if app_settings.print_line_numbers {
×
51
                    match current_mode {
×
52
                        ResymAppMode::Comparing(_, _, last_line_number, ..) => {
×
53
                            // Compute the columns' sizes from the number of digits
54
                            let char_count = last_line_number.checked_ilog10().unwrap_or(1) + 1;
×
55
                            let line_number_width = (char_count * line_number_digit_width) as f32;
×
56

57
                            // Old index + new index + code editor
58
                            (3, line_number_width)
×
59
                        }
60
                        ResymAppMode::Browsing(_, last_line_number, _) => {
×
61
                            // Compute the columns' sizes from the number of digits
62
                            let char_count = last_line_number.checked_ilog10().unwrap_or(1) + 1;
×
63
                            let line_number_width = (char_count * line_number_digit_width) as f32;
×
64

65
                            // Line numbers + code editor
66
                            (2, line_number_width)
×
67
                        }
68
                        _ => {
×
69
                            // Code editor only
70
                            (1, 0.0)
×
71
                        }
72
                    }
73
                } else {
74
                    // Code editor only
75
                    (1, 0.0)
×
76
                };
77

78
                egui::Grid::new("code_editor_grid")
×
79
                    .num_columns(num_colums)
×
80
                    .min_col_width(min_column_width)
×
81
                    .show(ui, |ui| {
×
82
                        match current_mode {
×
83
                            ResymAppMode::Comparing(
×
84
                                line_numbers_old,
×
85
                                line_numbers_new,
×
86
                                _,
×
87
                                _,
×
88
                                reconstructed_type_diff,
×
89
                            ) => {
×
90
                                // Line numbers
91
                                if app_settings.print_line_numbers {
×
92
                                    ui.add(
×
93
                                        egui::TextEdit::multiline(&mut line_numbers_old.as_str())
×
94
                                            .font(egui::FontId::monospace(
×
95
                                                app_settings.font_size as f32,
×
96
                                            ))
97
                                            .interactive(false)
×
98
                                            .desired_width(min_column_width),
×
99
                                    );
100
                                    ui.add(
×
101
                                        egui::TextEdit::multiline(&mut line_numbers_new.as_str())
×
102
                                            .font(egui::FontId::monospace(
×
103
                                                app_settings.font_size as f32,
×
104
                                            ))
105
                                            .interactive(false)
×
106
                                            .desired_width(min_column_width),
×
107
                                    );
108
                                }
109
                                // Text content
110
                                ui.add(
×
111
                                    egui::TextEdit::multiline(
×
112
                                        &mut reconstructed_type_diff.as_str(),
×
113
                                    )
114
                                    .code_editor()
×
115
                                    .layouter(&mut layouter),
×
116
                                );
117
                            }
118
                            ResymAppMode::Browsing(line_numbers, _, reconstructed_type_content) => {
×
119
                                // Line numbers
120
                                if app_settings.print_line_numbers {
×
121
                                    ui.add(
×
122
                                        egui::TextEdit::multiline(&mut line_numbers.as_str())
×
123
                                            .font(egui::FontId::monospace(
×
124
                                                app_settings.font_size as f32,
×
125
                                            ))
126
                                            .interactive(false)
×
127
                                            .desired_width(min_column_width),
×
128
                                    );
129
                                }
130
                                // Text content
131
                                ui.add(
×
132
                                    egui::TextEdit::multiline(
×
133
                                        &mut reconstructed_type_content.as_str(),
×
134
                                    )
135
                                    .code_editor()
×
136
                                    .layouter(&mut layouter),
×
137
                                );
138
                            }
139
                            ResymAppMode::Idle => {}
×
140
                        }
141
                    });
142
            });
143
    }
144
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc