From d14f27a428508d82f6dee9edce38713ef1c264a4 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Mon, 25 Mar 2024 18:13:10 +0100 Subject: [PATCH] document some stuff --- hui-derive/src/lib.rs | 1 + hui/src/frame.rs | 3 +++ hui/src/frame/nine_patch.rs | 14 ++++++++++++-- hui/src/frame/point.rs | 2 ++ hui/src/frame/stack.rs | 4 ++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/hui-derive/src/lib.rs b/hui-derive/src/lib.rs index 637b0a6..7b535bc 100644 --- a/hui-derive/src/lib.rs +++ b/hui-derive/src/lib.rs @@ -4,6 +4,7 @@ use proc_macro::TokenStream; use quote::quote; use syn::{parse_macro_input, DeriveInput}; +/// Implements `Signal` trait for the given type #[proc_macro_derive(Signal)] pub fn signal(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); diff --git a/hui/src/frame.rs b/hui/src/frame.rs index 2671209..52db5a9 100644 --- a/hui/src/frame.rs +++ b/hui/src/frame.rs @@ -1,3 +1,5 @@ +//! modular procedural background system + use glam::Vec2; use crate::draw::UiDrawCommandList; @@ -9,6 +11,7 @@ mod impls; pub use rect::FrameRect; +/// Trait for a drawable frame pub trait Frame { /// Draw the frame at the given position and size fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2); diff --git a/hui/src/frame/nine_patch.rs b/hui/src/frame/nine_patch.rs index 1af14dd..2b686a1 100644 --- a/hui/src/frame/nine_patch.rs +++ b/hui/src/frame/nine_patch.rs @@ -1,16 +1,26 @@ -use glam::{vec2, UVec2, Vec2, Vec4}; +//! nine-patch frame implementation +//! +//! A 9-patch image is an image that can be scaled in a way that preserves the corners and edges of the image while scaling the center. +//! This is useful for creating scalable UI elements like buttons, windows, etc. + +use glam::{vec2, UVec2, Vec2}; use crate::{color, draw::{ImageHandle, UiDrawCommand}, rect::{Corners, FillColor, Rect}}; use super::Frame; +/// Represents a 9-patch image asset #[derive(Clone, Copy, Debug)] pub struct NinePatchAsset { pub image: ImageHandle, - //TODO: remove this + //TODO: remove this: pub size: (u32, u32), pub scalable_region: Rect, } //TODO allow scaling/moving corners + +/// A 9-patch frame +/// +/// Can optionally be tinted with a color (works well with grayscale assets) #[derive(Clone, Copy, Debug)] pub struct NinePatchFrame { pub asset: NinePatchAsset, diff --git a/hui/src/frame/point.rs b/hui/src/frame/point.rs index 5d0660e..b5a9104 100644 --- a/hui/src/frame/point.rs +++ b/hui/src/frame/point.rs @@ -1,3 +1,5 @@ +//! frame-relative positioning/size + use glam::{Vec2, vec2}; use derive_more::{Add, AddAssign, Sub, SubAssign}; use crate::layout::{Size, Size2d}; diff --git a/hui/src/frame/stack.rs b/hui/src/frame/stack.rs index f6f6e78..5e21dee 100644 --- a/hui/src/frame/stack.rs +++ b/hui/src/frame/stack.rs @@ -1,7 +1,10 @@ +//! allows stacking two frames on top of each other + use glam::Vec2; use crate::draw::UiDrawCommandList; use super::Frame; +/// A frame that draws two frames on top of each other pub struct FrameStack(pub Box, pub Box); impl Frame for FrameStack { @@ -17,6 +20,7 @@ impl Frame for FrameStack { } pub trait FrameStackExt: Frame { + /// Stack another frame on top of this one fn stack(self, other: impl Frame + 'static) -> FrameStack; }