Skip to content

Commit

Permalink
docs: Add some minimal amount of rustdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
johanhelsing committed Feb 22, 2022
1 parent 6b2ff09 commit 548f505
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>) -> f32`.
pub sdf: Handle<Shader>,
/// Shader containing a wgsl function for the fill of the shape
///
/// The shader needs to have the signature `fn fill(distance: f32, color: vec4<f32>) -> vec4<f32>`.
pub fill: Handle<Shader>, // todo: wrap in newtypes?
/// The outer bounds for the shape, should be bigger than the sdf shape
pub frame: Frame,
}

Expand All @@ -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 (!)
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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,
Expand All @@ -57,6 +67,7 @@ pub mod prelude {
}

#[derive(Default)]
/// Main plugin for enabling rendering of Sdf shapes
pub struct SmudPlugin;

impl Plugin for SmudPlugin {
Expand Down
2 changes: 2 additions & 0 deletions src/shader_loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 548f505

Please sign in to comment.