summaryrefslogtreecommitdiff
path: root/src/panes/designer_view.rs
blob: 0255b40c26746f473b3cb4b8111e51cf1d92d6c9 (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
51
52
53
54
55
56
57
58
59
60
use iced::widget::{
    button, center, container, pane_grid, responsive, row, text, themer,
};
use iced::{Alignment, Length};
use material_theme::Theme;

use super::style;
use crate::icon;
use crate::types::{DesignerPane, Message, RenderedElement};

pub fn view<'a>(
    element_tree: Option<&'a RenderedElement>,
    designer_theme: iced::Theme,
    is_focused: bool,
) -> pane_grid::Content<'a, Message, Theme> {
    let el_tree: iced::Element<'a, Message> = match element_tree {
        Some(tree) => responsive(|size| {
            center(
                container(tree.clone())
                    .style(|theme| {
                        container::background(theme.palette().background)
                    })
                    .height(size.height * 0.5)
                    .width(size.height * 0.8),
            )
            .into()
        })
        .into(),
        None => center("Open a project or begin creating one").into(),
    };

    let content = container(themer(designer_theme, el_tree))
        .id(iced::widget::container::Id::new("drop_zone"))
        .height(Length::Fill)
        .width(Length::Fill);

    let title_bar = pane_grid::TitleBar::new(text("Designer").center())
        .controls(pane_grid::Controls::dynamic(
            row![
                button("Switch to Code view")
                    .on_press(Message::SwitchPage(DesignerPane::CodeView),)
            ]
            .align_y(Alignment::Center),
            row![
                button(icon::switch())
                    .on_press(Message::SwitchPage(DesignerPane::CodeView),)
            ]
            .align_y(Alignment::Center),
        ))
        .padding(10)
        .style(style::title_bar);

    pane_grid::Content::new(content)
        .title_bar(title_bar)
        .style(if is_focused {
            style::pane_focused
        } else {
            style::pane_active
        })
}