summaryrefslogtreecommitdiff
path: root/iced_builder/src/lib.rs
diff options
context:
space:
mode:
authorpml68 <contact@pml68.me>2024-10-04 00:44:02 +0200
committerpml68 <contact@pml68.me>2024-10-04 00:44:02 +0200
commit510d68b92972b99868e187dd5340f04780b4c354 (patch)
tree6d0937824d8606423b5afef2a16e182a3a984f8f /iced_builder/src/lib.rs
parentfeat: implement fmt::Display for RenderedElement, work on props (diff)
downloadiced-builder-510d68b92972b99868e187dd5340f04780b4c354.tar.gz
feat: update to iced 0.13.1, basic project state file, prepare for drag&drop
Diffstat (limited to 'iced_builder/src/lib.rs')
-rw-r--r--iced_builder/src/lib.rs85
1 files changed, 85 insertions, 0 deletions
diff --git a/iced_builder/src/lib.rs b/iced_builder/src/lib.rs
index e69de29..971e0e3 100644
--- a/iced_builder/src/lib.rs
+++ b/iced_builder/src/lib.rs
@@ -0,0 +1,85 @@
+pub mod codegen;
+pub mod types;
+
+use std::path::PathBuf;
+
+use iced::widget::{pane_grid, text_editor};
+use types::{project::Project, rendered_element::RenderedElement, DesignerPage};
+
+#[derive(Debug, Clone)]
+pub enum Error {
+ IOError(std::io::ErrorKind),
+ SerdeError(String),
+ FormatError(String),
+ DialogClosed,
+ String(String),
+}
+
+impl std::fmt::Display for Error {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ Self::SerdeError(string) | Self::FormatError(string) | Self::String(string) => {
+ write!(f, "{}", string)
+ }
+ Self::IOError(kind) => {
+ write!(f, "{}", kind)
+ }
+ Self::DialogClosed => {
+ write!(
+ f,
+ "The file dialog has been closed without selecting a valid option."
+ )
+ }
+ }
+ }
+}
+
+impl From<std::io::Error> for Error {
+ fn from(value: std::io::Error) -> Self {
+ Self::IOError(value.kind())
+ }
+}
+
+impl From<serde_json::Error> for Error {
+ fn from(value: serde_json::Error) -> Self {
+ Self::SerdeError(value.to_string())
+ }
+}
+
+impl From<rust_format::Error> for Error {
+ fn from(value: rust_format::Error) -> Self {
+ Self::FormatError(value.to_string())
+ }
+}
+
+impl From<&'static str> for Error {
+ fn from(value: &'static str) -> Self {
+ Self::String(value.to_owned())
+ }
+}
+
+#[derive(Debug, Clone)]
+pub enum Message {
+ ToggleTheme,
+ CopyCode,
+ SwitchPage(DesignerPage),
+ EditorAction(text_editor::Action),
+ DropNewElement(types::ElementName, iced::Point, iced::Rectangle),
+ HandleNew(
+ types::ElementName,
+ Vec<(iced::advanced::widget::Id, iced::Rectangle)>,
+ ),
+ MoveElement(RenderedElement, iced::Point, iced::Rectangle),
+ HandleMove(
+ RenderedElement,
+ Vec<(iced::advanced::widget::Id, iced::Rectangle)>,
+ ),
+ Resized(pane_grid::ResizeEvent),
+ Clicked(pane_grid::Pane),
+ PaneDragged(pane_grid::DragEvent),
+ NewFile,
+ OpenFile,
+ FileOpened(Result<(PathBuf, Project), Error>),
+ SaveFile,
+ FileSaved(Result<PathBuf, Error>),
+}