summaryrefslogtreecommitdiff
path: root/iced_builder/src/views/code_view.rs
blob: 98f0b48944a870adb7f4ae07477515375e92d59b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use super::style;
use crate::types::{DesignerPage, Message};
use iced::{
    highlighter,
    widget::{button, container, pane_grid, row, text, text_editor, tooltip, Space},
    Alignment, Font, Length, Theme,
};

pub fn view<'a>(
    editor_content: &'a text_editor::Content,
    theme: Theme,
    is_focused: bool,
) -> pane_grid::Content<'a, Message> {
    let title = row![
        text("Generated Code"),
        Space::with_width(Length::Fill),
        tooltip(
            button(container(text('\u{0e801}').font(Font::with_name("editor-icons"))).center_x(30))
                .on_press(Message::CopyCode),
            "Copy code to clipboard",
            tooltip::Position::FollowCursor
        ),
        Space::with_width(20),
        button("Switch to Designer view").on_press(Message::SwitchPage(DesignerPage::DesignerView))
    ]
    .align_y(Alignment::Center);
    let title_bar = pane_grid::TitleBar::new(title)
        .padding(10)
        .style(style::title_bar);
    pane_grid::Content::new(
        text_editor(editor_content)
            .on_action(Message::EditorAction)
            .highlight(
                "rs",
                if theme.to_string().contains("Dark") {
                    highlighter::Theme::SolarizedDark
                } else {
                    highlighter::Theme::InspiredGitHub
                },
            )
            .height(Length::Fill)
            .padding(20),
    )
    .title_bar(title_bar)
    .style(if is_focused {
        style::pane_focused
    } else {
        style::pane_active
    })
}