summaryrefslogtreecommitdiff
path: root/iced_builder/src/lib.rs
diff options
context:
space:
mode:
authorPolesznyák Márk László <116908301+pml68@users.noreply.github.com>2024-10-24 23:18:46 +0200
committerGitHub <noreply@github.com>2024-10-24 23:18:46 +0200
commitb351dd45dcd4b4c9142f069c62b51159c00922bf (patch)
treed2f24b449c3f82a9f844ce35198bad351c2ca8af /iced_builder/src/lib.rs
parentMerge pull request #1 from pml68/feat/codegen (diff)
parentfeat: implement d&d for existing elements (diff)
downloadiced-builder-b351dd45dcd4b4c9142f069c62b51159c00922bf.tar.gz
Merge pull request #2 from pml68/feat/drag-and-drop
Drag & Drop done
Diffstat (limited to '')
-rw-r--r--iced_builder/src/lib.rs91
1 files changed, 91 insertions, 0 deletions
diff --git a/iced_builder/src/lib.rs b/iced_builder/src/lib.rs
new file mode 100644
index 0000000..420b14c
--- /dev/null
+++ b/iced_builder/src/lib.rs
@@ -0,0 +1,91 @@
+pub mod types;
+
+use std::path::PathBuf;
+
+use iced::widget::{pane_grid, text_editor};
+use types::{
+ element_name::ElementName, project::Project, rendered_element::RenderedElement, DesignerPage,
+};
+
+#[derive(Debug, Clone)]
+pub enum Error {
+ IOError(std::io::ErrorKind),
+ SerdeError(String),
+ FormatError(String),
+ NonExistentElement,
+ 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::NonExistentElement => {
+ write!(f, "The element tree contains no matching element.")
+ }
+ 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),
+ RefreshEditorContent,
+ DropNewElement(ElementName, iced::Point, iced::Rectangle),
+ HandleNew(
+ ElementName,
+ Vec<(iced::advanced::widget::Id, iced::Rectangle)>,
+ ),
+ MoveElement(RenderedElement, iced::Point, iced::Rectangle),
+ HandleMove(
+ RenderedElement,
+ Vec<(iced::advanced::widget::Id, iced::Rectangle)>,
+ ),
+ PaneResized(pane_grid::ResizeEvent),
+ PaneClicked(pane_grid::Pane),
+ PaneDragged(pane_grid::DragEvent),
+ NewFile,
+ OpenFile,
+ FileOpened(Result<(PathBuf, Project), Error>),
+ SaveFile,
+ FileSaved(Result<PathBuf, Error>),
+}