summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main.rs125
1 files changed, 73 insertions, 52 deletions
diff --git a/src/main.rs b/src/main.rs
index 6ee558b..d3fafc6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,21 +1,24 @@
+mod codegen;
mod types;
use iced::{
- executor,
+ clipboard, executor,
highlighter::{self, Highlighter},
theme,
widget::{
button, column, container,
pane_grid::{self, Pane, PaneGrid},
- row, text, text_editor, Column,
+ row, text, text_editor, tooltip, Column, Space,
},
Alignment, Application, Color, Command, Element, Font, Length, Settings,
};
-use rust_format::{Formatter, RustFmt};
-use types::{DesignerPage, DesignerState};
+use types::{rendered_element::RenderedElement, DesignerPage, DesignerState};
fn main() -> iced::Result {
- App::run(Settings::default())
+ App::run(Settings {
+ fonts: vec![include_bytes!("../fonts/icons.ttf").as_slice().into()],
+ ..Settings::default()
+ })
}
struct App {
@@ -32,6 +35,7 @@ struct App {
#[derive(Debug, Clone)]
enum Message {
ToggleTheme,
+ CopyCode,
Resized(pane_grid::ResizeEvent),
Clicked(pane_grid::Pane),
}
@@ -64,13 +68,13 @@ impl Application for App {
focus: None,
designer_state: DesignerState {
designer_content: vec![],
- designer_page: DesignerPage::Designer,
+ designer_page: DesignerPage::CodeView,
},
element_list: vec!["Column", "Row", "PickList", "PaneGrid", "Button", "Text"]
.into_iter()
.map(|c| c.to_owned())
.collect(),
- editor_content: text_editor::Content::new(),
+ editor_content: text_editor::Content::with_text(&RenderedElement::test()),
},
Command::none(),
)
@@ -98,6 +102,7 @@ impl Application for App {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::ToggleTheme => self.dark_theme = !self.dark_theme,
+ Message::CopyCode => return clipboard::write(self.editor_content.text()),
Message::Resized(pane_grid::ResizeEvent { split, ratio }) => {
self.pane_state.resize(split, ratio);
}
@@ -117,27 +122,72 @@ impl Application for App {
let pane_grid = PaneGrid::new(&self.pane_state, |id, pane, _is_maximized| {
let is_focused = Some(id) == self.focus;
match pane {
- Panes::Designer => {
- let content = column![text("Designer")]
- .align_items(Alignment::Center)
- .height(Length::Fill)
- .width(Length::Fill);
- let title = text("Designer").style(if is_focused {
- PANE_ID_COLOR_FOCUSED
- } else {
- PANE_ID_COLOR_UNFOCUSED
- });
- let title_bar = pane_grid::TitleBar::new(title)
- .padding(10)
- .style(style::title_bar);
- pane_grid::Content::new(content)
+ Panes::Designer => match self.designer_state.designer_page {
+ DesignerPage::Designer => {
+ let content = column![text("Designer"),]
+ .align_items(Alignment::Center)
+ .height(Length::Fill)
+ .width(Length::Fill);
+ let title = text("Designer").style(if is_focused {
+ PANE_ID_COLOR_FOCUSED
+ } else {
+ PANE_ID_COLOR_UNFOCUSED
+ });
+ let title_bar = pane_grid::TitleBar::new(title)
+ .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
+ })
+ }
+ DesignerPage::CodeView => {
+ let title = row![
+ text("Generated Code").style(if is_focused {
+ PANE_ID_COLOR_FOCUSED
+ } else {
+ PANE_ID_COLOR_UNFOCUSED
+ }),
+ Space::with_width(Length::Fill),
+ tooltip(
+ button(
+ container(
+ text('\u{0e801}').font(Font::with_name("editor-icons"))
+ )
+ .width(30)
+ .center_x()
+ )
+ .on_press(Message::CopyCode),
+ "Copy code to clipboard",
+ tooltip::Position::Left
+ )
+ ];
+ let title_bar = pane_grid::TitleBar::new(title)
+ .padding(10)
+ .style(style::title_bar);
+ pane_grid::Content::new(
+ text_editor(&self.editor_content)
+ .highlight::<Highlighter>(
+ highlighter::Settings {
+ theme: highlighter::Theme::Base16Mocha,
+ extension: "rs".to_string(),
+ },
+ |highlight, _theme| highlight.to_format(),
+ )
+ .height(Length::Fill)
+ .padding(20),
+ )
.title_bar(title_bar)
.style(if is_focused {
style::pane_focused
} else {
style::pane_active
})
- }
+ }
+ },
Panes::ElementList => {
let items_list = items_list_view(&self.element_list);
let content = column![items_list]
@@ -159,36 +209,7 @@ impl Application for App {
} else {
style::pane_active
})
- } //Panes::CodeView => {
- // let title = text("Generated Code").style(if is_focused {
- // PANE_ID_COLOR_FOCUSED
- // } else {
- // PANE_ID_COLOR_UNFOCUSED
- // });
- // let title_bar =
- // pane_grid::TitleBar::new(title)
- // .padding(10)
- // .style(if is_focused {
- // style::title_bar_focused
- // } else {
- // style::title_bar_active
- // });
- // pane_grid::Content::new(
- // text_editor(&self.editor_content).highlight::<Highlighter>(
- // highlighter::Settings {
- // theme: highlighter::Theme::Base16Mocha,
- // extension: "rs".to_string(),
- // },
- // |highlight, _theme| highlight.to_format(),
- // ),
- // )
- // .title_bar(title_bar)
- // .style(if is_focused {
- // style::pane_focused
- // } else {
- // style::pane_active
- // })
- //}
+ }
}
})
.width(Length::Fill)