feat: added max docs and 1 feat in ewwii_plugin_api
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ewwii_plugin_api"
|
||||
version = "0.3.2"
|
||||
version = "0.4.0"
|
||||
authors = ["byson94 <byson94wastaken@gmail.com>"]
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
@@ -10,8 +10,12 @@ homepage = "https://github.com/byson94/ewwii"
|
||||
|
||||
[features]
|
||||
default = ["include-gtk4", "include-rhai"]
|
||||
include-gtk4 = ["gtk4"]
|
||||
include-rhai = ["rhai"]
|
||||
|
||||
## Include the gtk4 dependency
|
||||
include-gtk4 = ["dep:gtk4"]
|
||||
|
||||
## Include the rhai dependency
|
||||
include-rhai = ["dep:rhai"]
|
||||
|
||||
[dependencies]
|
||||
rhai = { workspace = true, optional = true }
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
pub struct ExamplePlugin;
|
||||
|
||||
impl crate::Plugin for ExamplePlugin {
|
||||
/// Example code that initalizes the plugin
|
||||
fn init(&self, host: &dyn crate::EwwiiAPI) {
|
||||
host.log("Example plugin says Hello!");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,69 @@
|
||||
//! Module implementing macros
|
||||
|
||||
/// Macro to implement and export a plugin in a single step.
|
||||
/// With this macro, users can write their plugin code directly
|
||||
/// without having to manually implement each trait.
|
||||
///
|
||||
/// ## Example
|
||||
///
|
||||
/// The following example shows how you can use this macro to
|
||||
/// easily make plugins in a single step.
|
||||
///
|
||||
/// ```rust
|
||||
/// auto_plugin!(MyPluginName, {
|
||||
/// // host variable is passed in automatically
|
||||
/// host.log("Easy, huh?");
|
||||
/// })
|
||||
///
|
||||
/// ```
|
||||
///
|
||||
/// That's it! The plugin is ready.
|
||||
///
|
||||
/// ## When not to use it
|
||||
///
|
||||
/// This macro shall not be used if you want to have
|
||||
/// fields in your plugin.
|
||||
///
|
||||
/// ```rust
|
||||
/// struct MyPluginName {
|
||||
/// awesome_field: String
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// For a structure like the above, you should do this instead:
|
||||
///
|
||||
/// ```rust
|
||||
/// use ewwii_plugin_api::{EwwiiAPI, Plugin, export_plugin};
|
||||
///
|
||||
/// pub struct DummyStructure;
|
||||
///
|
||||
/// impl Plugin for DummyStructure {
|
||||
/// // critical for ewwii to launch the plugin
|
||||
/// fn init(&self, host: &dyn EwwiiAPI) {
|
||||
/// // will be printed by the host
|
||||
/// host.log("Plugin says Hello!");
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// // Critical for ewwii to load the plugin
|
||||
/// export_plugin!(DummyStructure);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! auto_plugin {
|
||||
($struct_name:ident, $init_block:block) => {
|
||||
pub struct $struct_name;
|
||||
|
||||
// Implement the Plugin trait
|
||||
impl crate::Plugin for $struct_name {
|
||||
fn init(&self, host: &dyn crate::EwwiiAPI) {
|
||||
$init_block
|
||||
}
|
||||
}
|
||||
|
||||
export_plugin!($struct_name);
|
||||
};
|
||||
}
|
||||
|
||||
/// Automatically implements `create_plugin` for a given fieldless structure
|
||||
#[macro_export]
|
||||
macro_rules! export_plugin {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
//!
|
||||
//! ```rust
|
||||
//! use ewwii_plugin_api::{EwwiiAPI, Plugin, export_plugin};
|
||||
//!
|
||||
//! pub struct DummyStructure;
|
||||
//!
|
||||
//! impl Plugin for DummyStructure {
|
||||
@@ -44,7 +45,16 @@ pub trait EwwiiAPI: Send + Sync {
|
||||
fn error(&self, msg: &str);
|
||||
|
||||
// == Rhai Manipulation Stuff == //
|
||||
/// Perform actions on the latest rhai engine
|
||||
/// _(include-rhai)_ Perform actions on the latest rhai engine.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// host.rhai_engine_action(Box::new(|eng| {
|
||||
/// // eng = rhai::Engine
|
||||
/// eng.set_max_expr_depths(128, 128);
|
||||
/// }));
|
||||
/// ```
|
||||
#[cfg(feature = "include-rhai")]
|
||||
fn rhai_engine_action(&self, f: Box<dyn FnOnce(&mut Engine) + Send>) -> Result<(), String>;
|
||||
|
||||
@@ -52,7 +62,16 @@ pub trait EwwiiAPI: Send + Sync {
|
||||
/// Get the list of all widget id's
|
||||
fn list_widget_ids(&self) -> Result<Vec<u64>, String>;
|
||||
|
||||
/// Perform actions on the latest widget registry
|
||||
/// _(include-gtk4)_ Perform actions on the latest widget registry.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// host.widget_reg_action(Box::new(|wrg| {
|
||||
/// // wrg = widget_backend::WidgetRegistryRepr
|
||||
/// // The gtk4::Widget can be modified here.
|
||||
/// }));
|
||||
/// ```
|
||||
#[cfg(feature = "include-gtk4")]
|
||||
fn widget_reg_action(
|
||||
&self,
|
||||
@@ -60,7 +79,24 @@ pub trait EwwiiAPI: Send + Sync {
|
||||
) -> Result<(), String>;
|
||||
}
|
||||
|
||||
/// The API format that the plugin should follow
|
||||
/// The API format that the plugin should follow.
|
||||
/// This trait should be implemented for a structure and
|
||||
/// that structure should be exported via FFI.
|
||||
///
|
||||
/// ## Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use ewwii_plugin_api::{Plugin, export_plugin};
|
||||
///
|
||||
/// sturct MyStruct;
|
||||
///
|
||||
/// impl Plugin for MyStruct {
|
||||
/// /* Implementation Skipped */
|
||||
/// }
|
||||
///
|
||||
/// // Automatically does all the FFI related exports
|
||||
/// export_plugin!(MyStruct);
|
||||
/// ```
|
||||
pub trait Plugin: Send + Sync {
|
||||
/// Function ran by host to startup plugin (and its a must-have for plugin loading)
|
||||
fn init(&self, host: &dyn EwwiiAPI);
|
||||
|
||||
@@ -6,7 +6,7 @@ mod gtk4_included {
|
||||
use gtk4::Widget as GtkWidget;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// A representation of widget registry which holds all the
|
||||
/// _(include-gtk4)_ 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
|
||||
|
||||
Reference in New Issue
Block a user