1use std::time::Instant;
2
3use ui::{div, prelude::*};
4
5use crate::{CsvPreviewView, settings::FontType};
6
7impl Render for CsvPreviewView {
8 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
9 let theme = cx.theme();
10
11 self.performance_metrics.rendered_indices.clear();
12 let render_prep_start = Instant::now();
13 let table_with_settings = v_flex()
14 .size_full()
15 .p_4()
16 .bg(theme.colors().editor_background)
17 .track_focus(&self.focus_handle)
18 .child({
19 if self.engine.contents.number_of_cols == 0 {
20 div()
21 .flex()
22 .items_center()
23 .justify_center()
24 .h_32()
25 .text_ui(cx)
26 .map(|div| match self.settings.font_type {
27 FontType::Ui => div.font_ui(cx),
28 FontType::Monospace => div.font_buffer(cx),
29 })
30 .text_color(cx.theme().colors().text_muted)
31 .child("No CSV content to display")
32 .into_any_element()
33 } else {
34 self.create_table(&self.column_widths.widths, cx)
35 }
36 });
37
38 let render_prep_duration = render_prep_start.elapsed();
39 self.performance_metrics.timings.insert(
40 "render_prep",
41 (render_prep_duration, std::time::Instant::now()),
42 );
43
44 div()
45 .relative()
46 .w_full()
47 .h_full()
48 .child(table_with_settings)
49 }
50}