diff options
Diffstat (limited to '')
| -rw-r--r-- | fonts/icons.ttf | bin | 0 -> 6352 bytes | |||
| -rw-r--r-- | src/codegen/mod.rs | 37 | ||||
| -rw-r--r-- | src/main.rs | 37 |
3 files changed, 52 insertions, 22 deletions
diff --git a/fonts/icons.ttf b/fonts/icons.ttf Binary files differnew file mode 100644 index 0000000..393c692 --- /dev/null +++ b/fonts/icons.ttf diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index bc3c379..2dd9cff 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use rust_format::{Config, Edition, Formatter, RustFmt}; use crate::types::{rendered_element::RenderedElement, ElementName}; @@ -23,9 +25,8 @@ impl RenderedElement { match self.name { ElementName::Column | ElementName::Row | ElementName::Container => { for element in &self.child_elements { - let mut children = String::new(); - - (imports, children) = element.codegen(); + let (c_imports, children) = element.codegen(); + imports = format!("{imports}{c_imports}"); elements = format!("{elements}{},", children); } } @@ -73,11 +74,11 @@ impl RenderedElement { } ElementName::Image(path) => { imports = format!("{imports}image,"); - view = format!("{view}\nimage({}){props}", path.display().to_string()); + view = format!("{view}\nimage(\"{}\"){props}", path.display().to_string()); } ElementName::SVG(path) => { imports = format!("{imports}svg,"); - view = format!("{view}\nsvg({}){props}", path.display().to_string()); + view = format!("{view}\nsvg(\"{}\"){props}", path.display().to_string()); } } @@ -116,11 +117,11 @@ impl RenderedElement { iced::Theme::{} }} - fn update(&mut self, message: Message) {{ + fn update(&mut self, message: Self::Message) {{ }} - fn view(&self) -> Element<Message> {{ + fn view(&self) -> Element<Self::Message> {{ {view}.into() }} }}"#, @@ -130,20 +131,28 @@ impl RenderedElement { "default()".to_owned() } ); - - Ok(RustFmt::default().format_str(app_code)?) + let config = Config::new_str() + .edition(Edition::Rust2021) + .option("trailing_comma", "Never") + .option("imports_granularity", "Crate"); + let rustfmt = RustFmt::from_config(config); + Ok(rustfmt.format_str(app_code)?) } pub fn test() -> String { let mut text1 = RenderedElement::new(ElementName::Text("wow")); - text1.set_property("padding", "[10, 20]"); - text1.set_property("spacing", "20.0"); - text1.set_property("max_height", "120.5"); - text1.set_property("max_width", "230"); + text1.set_property("height", "120.5"); + text1.set_property("width", "230"); let element = RenderedElement::new(ElementName::Container).push(RenderedElement::from_vec( ElementName::Row, - vec![text1, RenderedElement::new(ElementName::Text("heh"))], + vec![ + text1, + RenderedElement::new(ElementName::Text("heh")), + RenderedElement::new(ElementName::SVG(PathBuf::from( + "/mnt/drive_d/git/obs-website/src/lib/assets/bars-solid.svg", + ))), + ], )); element.app_code("new app", None).unwrap() diff --git a/src/main.rs b/src/main.rs index 5b691bb..d3fafc6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,20 +2,23 @@ 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 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), } @@ -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); } @@ -140,11 +145,26 @@ impl Application for App { }) } DesignerPage::CodeView => { - let title = text("Generated Code").style(if is_focused { - PANE_ID_COLOR_FOCUSED - } else { - PANE_ID_COLOR_UNFOCUSED - }); + 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); @@ -157,6 +177,7 @@ impl Application for App { }, |highlight, _theme| highlight.to_format(), ) + .height(Length::Fill) .padding(20), ) .title_bar(title_bar) |
