From 8d025d1958c36c56ee558b3f8122c2b782bb9112 Mon Sep 17 00:00:00 2001 From: Byson94 Date: Sat, 11 Oct 2025 09:38:39 +0530 Subject: [PATCH] feat: improving the ewwii_plugin_api crate and fixing issues --- Cargo.lock | 2 +- crates/ewwii_plugin_api/Cargo.toml | 11 +++++--- crates/ewwii_plugin_api/src/export_macros.rs | 4 +-- crates/ewwii_plugin_api/src/lib.rs | 3 +++ crates/ewwii_plugin_api/src/widget_backend.rs | 25 +++++++++++-------- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 75e3d7c..d2489ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -527,7 +527,7 @@ dependencies = [ [[package]] name = "ewwii_plugin_api" -version = "0.3.0" +version = "0.3.1" dependencies = [ "gtk4", "rhai", diff --git a/crates/ewwii_plugin_api/Cargo.toml b/crates/ewwii_plugin_api/Cargo.toml index 9d04811..0b8b651 100644 --- a/crates/ewwii_plugin_api/Cargo.toml +++ b/crates/ewwii_plugin_api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ewwii_plugin_api" -version = "0.3.0" +version = "0.3.1" authors = ["byson94 "] edition = "2021" license = "GPL-3.0-or-later" @@ -8,6 +8,11 @@ description = "A shared library for building plugins for ewwii" repository = "https://github.com/byson94/ewwii" homepage = "https://github.com/byson94/ewwii" +[features] +default = ["include-gtk4", "include-rhai"] +include-gtk4 = ["gtk4"] +include-rhai = ["rhai"] + [dependencies] -rhai.workspace = true -gtk4.workspace = true \ No newline at end of file +rhai = {workspace = true, optional = true } +gtk4 = { workspace = true, optional = true } \ No newline at end of file diff --git a/crates/ewwii_plugin_api/src/export_macros.rs b/crates/ewwii_plugin_api/src/export_macros.rs index 1fdde65..618ffcd 100644 --- a/crates/ewwii_plugin_api/src/export_macros.rs +++ b/crates/ewwii_plugin_api/src/export_macros.rs @@ -3,7 +3,7 @@ /// Automatically implements `create_plugin` for a given fieldless structure #[macro_export] macro_rules! export_plugin { - ($plugin_struct:ty) => { + ($plugin_struct:path) => { #[unsafe(no_mangle)] pub extern "C" fn create_plugin() -> Box { Box::new($plugin_struct) @@ -16,7 +16,7 @@ macro_rules! export_plugin { /// This macro expects the structure to have fields and also implement a `default()` method. #[macro_export] macro_rules! export_stateful_plugin { - ($plugin_struct:ty) => { + ($plugin_struct:path) => { #[unsafe(no_mangle)] pub extern "C" fn create_plugin() -> Box { Box::new(<$plugin_struct>::default()) diff --git a/crates/ewwii_plugin_api/src/lib.rs b/crates/ewwii_plugin_api/src/lib.rs index 28b39fc..729d03b 100644 --- a/crates/ewwii_plugin_api/src/lib.rs +++ b/crates/ewwii_plugin_api/src/lib.rs @@ -28,6 +28,7 @@ mod export_macros; pub mod example; pub mod widget_backend; +#[cfg(feature = "include-rhai")] use rhai::Engine; /// The shared trait defining the Ewwii plugin API @@ -44,6 +45,7 @@ pub trait EwwiiAPI: Send + Sync { // == Rhai Manipulation Stuff == // /// Perform actions on the latest rhai engine + #[cfg(feature = "include-rhai")] fn rhai_engine_action(&self, f: Box) -> Result<(), String>; // == Widget Rendering & Logic == // @@ -51,6 +53,7 @@ pub trait EwwiiAPI: Send + Sync { fn list_widget_ids(&self) -> Result, String>; /// Perform actions on the latest widget registry + #[cfg(feature = "include-gtk4")] fn widget_reg_action( &self, f: Box, diff --git a/crates/ewwii_plugin_api/src/widget_backend.rs b/crates/ewwii_plugin_api/src/widget_backend.rs index 387f322..47abfee 100644 --- a/crates/ewwii_plugin_api/src/widget_backend.rs +++ b/crates/ewwii_plugin_api/src/widget_backend.rs @@ -1,15 +1,20 @@ //! Module exposing structures and types from the //! Widget rendering and definition backend in ewwii. -use gtk4::Widget as GtkWidget; -use std::collections::HashMap; +#[cfg(feature = "include-gtk4")] +mod gtk4_included { + use gtk4::Widget as GtkWidget; + use std::collections::HashMap; -/// A representation of widget registry which holds all the -/// information needed for the dynamic runtime engine in ewwii. -/// -/// Not every change in this structure will be represented in the -/// original WidgetRegistry in ewwii. Only the change on gtk4::Widget -/// is reflected back. -pub struct WidgetRegistryRepr<'a> { - pub widgets: HashMap, + /// A representation of widget registry which holds all the + /// information needed for the dynamic runtime engine in ewwii. + /// + /// Not every change in this structure will be represented in the + /// original WidgetRegistry in ewwii. Only the change on gtk4::Widget + /// is reflected back. + pub struct WidgetRegistryRepr<'a> { + pub widgets: HashMap, + } } + +pub use gtk4_included::*; \ No newline at end of file