diff --git a/src/bundle.rs b/src/bundle.rs index 7623d2a..b370cc5 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -3,6 +3,7 @@ use bevy::prelude::*; use crate::SmudShape; #[derive(Bundle, Default, Clone)] +/// Bundle with all the components needed for drawing an sdf shape in 2d world space pub struct ShapeBundle { pub shape: SmudShape, pub transform: Transform, @@ -14,6 +15,7 @@ pub struct ShapeBundle { } #[derive(Bundle, Default, Clone)] +/// Bundle with all the components used for drawing an sdf shape as a bevy UI node pub struct UiShapeBundle { /// Describes the size of the node pub node: Node, diff --git a/src/components.rs b/src/components.rs index 7edc4de..bf6e9a3 100644 --- a/src/components.rs +++ b/src/components.rs @@ -3,10 +3,19 @@ use bevy::{ecs::query::QueryItem, prelude::*, render::render_component::ExtractC use crate::DEFAULT_FILL_HANDLE; #[derive(Component, Debug, Clone)] +/// Main component used for describing an sdf shape pub struct SmudShape { + /// The color used by the fill shader pub color: Color, + /// Shader containing a wgsl function for a signed distance field + /// + /// The shader needs to have the signature `fn sdf(p: vec2) -> f32`. pub sdf: Handle, + /// Shader containing a wgsl function for the fill of the shape + /// + /// The shader needs to have the signature `fn fill(distance: f32, color: vec4) -> vec4`. pub fill: Handle, // todo: wrap in newtypes? + /// The outer bounds for the shape, should be bigger than the sdf shape pub frame: Frame, } @@ -30,6 +39,7 @@ impl ExtractComponent for SmudShape { } } +/// Bounds for describing how far the fragment shader of a shape will reach, should be bigger than the shape unless you want to clip it #[derive(Debug, Clone, Copy)] pub enum Frame { /// A quad with a given half-size (!) diff --git a/src/lib.rs b/src/lib.rs index ce2922f..89d13b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,7 @@ +//! See the [readme](https://github.com/johanhelsing/bevy_smud) and +//! [examples](https://github.com/johanhelsing/bevy_smud/tree/main/examples) for +//! usage. + use std::cmp::Ordering; use bevy::{ @@ -49,6 +53,12 @@ mod sdf_assets; mod shader_loading; mod ui; +/// Re-export of the essentials needed for rendering shapes +/// +/// Intended to be included at the top of your file to minimize the amount of import noise. +/// ``` +/// use bevy_smud::prelude::*; +/// ``` pub mod prelude { pub use crate::{ sdf_assets::SdfAssets, Frame, ShapeBundle, SmudPlugin, SmudShape, UiShapeBundle, @@ -57,6 +67,7 @@ pub mod prelude { } #[derive(Default)] +/// Main plugin for enabling rendering of Sdf shapes pub struct SmudPlugin; impl Plugin for SmudPlugin { diff --git a/src/shader_loading.rs b/src/shader_loading.rs index ae80e1f..986b71e 100644 --- a/src/shader_loading.rs +++ b/src/shader_loading.rs @@ -16,10 +16,12 @@ pub const FRAGMENT_SHADER_HANDLE: HandleUntyped = HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 10370213491934870425); const FRAGMENT_SHADER_IMPORT: &str = "bevy_smud::fragment"; +/// The default fill used by `SmudShape` pub const DEFAULT_FILL_HANDLE: HandleUntyped = HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 18184663565780163454); const DEFAULT_FILL_IMPORT: &str = "bevy_smud::default_fill"; +/// Simple single-colored filled fill pub const SIMPLE_FILL_HANDLE: HandleUntyped = HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 16286090377316294491); const SIMPLE_FILL_IMPORT: &str = "bevy_smud::simple_fill";