From e8d36bd018177e4ccc0ae27ce8f21984d31d948a Mon Sep 17 00:00:00 2001 From: pml68 Date: Sat, 4 Jan 2025 14:25:14 +0100 Subject: feat: add custom theme codegen for `Project` --- iced_builder/src/main.rs | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'iced_builder/src/main.rs') diff --git a/iced_builder/src/main.rs b/iced_builder/src/main.rs index 437410a..b30afaa 100644 --- a/iced_builder/src/main.rs +++ b/iced_builder/src/main.rs @@ -1,20 +1,30 @@ +#![feature(test)] +mod config; +mod dialogs; +mod environment; +mod error; +mod icon; +mod panes; +mod theme; +mod types; +mod widget; + use std::path::PathBuf; +use config::Config; +use dialogs::{error_dialog, unsaved_changes_dialog, warning_dialog}; +use error::Error; use iced::advanced::widget::Id; use iced::widget::pane_grid::{self, Pane, PaneGrid}; use iced::widget::{container, pick_list, row, text_editor, Column}; use iced::{clipboard, keyboard, Alignment, Element, Length, Task, Theme}; -use iced_anim::{Animation, Spring}; -use iced_builder::config::Config; -use iced_builder::dialogs::{ - error_dialog, unsaved_changes_dialog, warning_dialog, -}; -use iced_builder::panes::{code_view, designer_view, element_list}; -use iced_builder::types::{ - Action, DesignerPage, ElementName, Message, Project, -}; -use iced_builder::{icon, Error}; +use iced_anim::transition::Easing; +use iced_anim::{Animated, Animation}; +use panes::{code_view, designer_view, element_list}; use tokio::runtime; +use types::{Action, DesignerPage, ElementName, Message, Project}; + +//pub(crate) type Result = core::result::Result; fn main() -> Result<(), Box> { let config_load = { @@ -40,7 +50,7 @@ struct App { project_path: Option, project: Project, config: Config, - theme: Spring, + theme: Animated, pane_state: pane_grid::State, focus: Option, designer_page: DesignerPage, @@ -73,7 +83,7 @@ impl App { if let Some(path) = config.last_project.clone() { if path.exists() && path.is_file() { task = Task::perform( - Project::from_path(path), + Project::from_path(path, config.clone()), Message::FileOpened, ); } else { @@ -91,7 +101,7 @@ impl App { project_path: None, project: Project::new(), config, - theme: Spring::new(theme), + theme: Animated::new(theme, Easing::EASE_IN), pane_state: state, focus: None, designer_page: DesignerPage::DesignerView, @@ -137,7 +147,7 @@ impl App { } } Message::RefreshEditorContent => { - match self.project.clone().app_code(&self.config) { + match self.project.app_code(&self.config) { Ok(code) => { self.editor_content = text_editor::Content::with_text(&code); @@ -238,13 +248,13 @@ impl App { self.is_loading = true; return Task::perform( - Project::from_file(), + Project::from_file(self.config.clone()), Message::FileOpened, ); } else if unsaved_changes_dialog("You have unsaved changes. Do you wish to discard these and open another project?") { self.is_dirty = false; self.is_loading = true; - return Task::perform(Project::from_file(), Message::FileOpened); + return Task::perform(Project::from_file(self.config.clone()), Message::FileOpened); } } } @@ -254,10 +264,11 @@ impl App { match result { Ok((path, project)) => { - self.project = project.clone(); + self.project = project; self.project_path = Some(path); self.editor_content = text_editor::Content::with_text( - &project + &self + .project .app_code(&self.config) .unwrap_or_else(|err| err.to_string()), ); -- cgit v1.2.3