feat: improving the ewwii_plugin_api crate and fixing issues

This commit is contained in:
Byson94
2025-10-11 09:38:39 +05:30
parent 732acbdf5c
commit 8d025d1958
5 changed files with 29 additions and 16 deletions

2
Cargo.lock generated
View File

@@ -527,7 +527,7 @@ dependencies = [
[[package]]
name = "ewwii_plugin_api"
version = "0.3.0"
version = "0.3.1"
dependencies = [
"gtk4",
"rhai",

View File

@@ -1,6 +1,6 @@
[package]
name = "ewwii_plugin_api"
version = "0.3.0"
version = "0.3.1"
authors = ["byson94 <byson94wastaken@gmail.com>"]
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
rhai = {workspace = true, optional = true }
gtk4 = { workspace = true, optional = true }

View File

@@ -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<dyn $crate::Plugin> {
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<dyn $crate::Plugin> {
Box::new(<$plugin_struct>::default())

View File

@@ -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<dyn FnOnce(&mut Engine) + Send>) -> Result<(), String>;
// == Widget Rendering & Logic == //
@@ -51,6 +53,7 @@ pub trait EwwiiAPI: Send + Sync {
fn list_widget_ids(&self) -> Result<Vec<u64>, String>;
/// Perform actions on the latest widget registry
#[cfg(feature = "include-gtk4")]
fn widget_reg_action(
&self,
f: Box<dyn FnOnce(&mut widget_backend::WidgetRegistryRepr) + Send>,

View File

@@ -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<u64, &'a mut GtkWidget>,
/// 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<u64, &'a mut GtkWidget>,
}
}
pub use gtk4_included::*;