Force Smith Macros
Procedural macros for the Force Smith force-directed graph layout library.
Overview
This crate provides derive macros that simplify working with Force Smith's visualizer by automatically generating trait implementations for parameterized layout algorithms.
Macros
#[derive(Parameterized)]
Automatically implements the Parameterized trait for structs, allowing them to expose their fields as adjustable parameters in the Force Smith visualizer UI.
Usage
use *;
This automatically generates:
get_parameters(&self) -> Vec<Parameter>- Returns all parameters with their current valuesupdate_parameters(&mut self, parameters: &[Parameter])- Updates parameters from UI changes
Supported Types
f32- Floating point parameters (displayed as draggable value in UI)i32- Integer parameters (displayed as draggable value in UI)bool- Boolean parameters (displayed as checkbox in UI)
Attributes
#[parameter(name = "Display Name")]- Marks a field as a parameter with a custom display name- If
nameis not specified, the field name is used
- If
Example
use *;
When used with the visualizer, these parameters will appear in the "Parameter Configuration" UI window and can be adjusted in real-time while the layout algorithm runs.
Live Example
See a complete working example with multiple parameter types:
This example demonstrates:
- Multiple
f32parameters (temperature, spring length, stiffness, etc.) - An
i32parameter (iterations per cool) - Multiple
boolparameters (gravity enabled) - How parameters appear and behave in the visualizer UI
- Real-time updates affecting algorithm behavior
Requirements
This crate is designed to work with Force Smith 1.0+ and requires the visualizer feature to be enabled.
Integration
The macro generates code that integrates with Force Smith's visualizer module. The generated implementation uses:
force_smith::visualizer::layout_trait::Parameterized- The trait being implementedforce_smith::visualizer::layout_trait::ToParameterValue- For converting Rust types to parameter valuesforce_smith::visualizer::layout_trait::FromParameterValue- For converting parameter values back to Rust typesforce_smith::prelude::Parameter- The parameter type used in the visualizer
License
MIT License - see LICENSE file for details.