From 9f0809c61cebc6b012d7d49abc8feb74d896fa7c Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Sat, 2 Mar 2024 01:07:53 +0100 Subject: [PATCH] update docs --- hui/src/element.rs | 5 ++++- hui/src/element/builtin/container.rs | 20 +++++++++++++++++++- hui/src/element/builtin/progress_bar.rs | 9 +++++++++ hui/src/element/builtin/text.rs | 13 +++++++++++++ hui/src/element/builtin/transformer.rs | 13 +++++++++---- 5 files changed, 54 insertions(+), 6 deletions(-) diff --git a/hui/src/element.rs b/hui/src/element.rs index ffca9b4..bb5b0a0 100644 --- a/hui/src/element.rs +++ b/hui/src/element.rs @@ -1,4 +1,5 @@ -//! element API, built-in elements like `Container`, `Button`, `Text`, etc. +//! element API and built-in elements like `Container`, `Button`, `Text`, etc. + use std::any::Any; use crate::{ draw::UiDrawCommandList, @@ -84,6 +85,7 @@ impl ElementList { } } +/// Extension trait for [`UiElement`] that adds the [`add_child`] and [`add_root`] methods pub trait UiElementExt: UiElement { /// Add element as a child/nested element. fn add_child(self, ui: &mut ElementList); @@ -96,6 +98,7 @@ impl UiElementExt for T { fn add_child(self, ui: &mut ElementList) { ui.add(self) } + fn add_root(self, ui: &mut UiInstance, max_size: glam::Vec2) { ui.add(self, max_size); } diff --git a/hui/src/element/builtin/container.rs b/hui/src/element/builtin/container.rs index 9cddc37..5c18382 100644 --- a/hui/src/element/builtin/container.rs +++ b/hui/src/element/builtin/container.rs @@ -1,3 +1,5 @@ +//! a container element that can hold and layout multiple children elements + use derive_setters::Setters; use glam::{Vec2, vec2}; use crate::{ @@ -14,26 +16,42 @@ use crate::{ // pub width: f32, // } -///XXX: add Order/Direction::Forward/Reverse or sth? +//XXX: add Order/Direction::Forward/Reverse or sth? //TODO: clip children flag //TODO: borders //TODO: min/max size +/// A container element that can hold and layout multiple children elements #[derive(Setters)] #[setters(prefix = "with_")] pub struct Container { + /// Size of the container #[setters(into)] pub size: Size2d, + + /// Layout direction (horizontal/vertical) pub direction: UiDirection, + + /// Gap between children elements pub gap: f32, + + /// Padding inside the container (distance from the edges to the children elements) #[setters(into)] pub padding: Sides, + + /// Alignment of the children elements on X and Y axis #[setters(into)] pub align: Alignment2d, + + /// Background color of the container #[setters(into)] pub background: RectBackground, + + /// Corner radius of the background rectangle #[setters(into)] pub corner_radius: Corners, + + /// List of children elements #[setters(skip)] pub children: ElementList, } diff --git a/hui/src/element/builtin/progress_bar.rs b/hui/src/element/builtin/progress_bar.rs index 7d391b2..5c72e17 100644 --- a/hui/src/element/builtin/progress_bar.rs +++ b/hui/src/element/builtin/progress_bar.rs @@ -12,13 +12,22 @@ use crate::{ #[derive(Debug, Clone, Copy, Setters)] #[setters(prefix = "with_")] pub struct ProgressBar { + /// Current progress, should be in the range 0.0..=1.0 pub value: f32, + + /// Size of the progress bar element #[setters(into)] pub size: Size2d, + + /// Foreground (bar) color #[setters(into)] pub foreground: RectBackground, + + /// Background color #[setters(into)] pub background: RectBackground, + + /// Corner radius of the progress bar #[setters(into)] pub corner_radius: Corners, } diff --git a/hui/src/element/builtin/text.rs b/hui/src/element/builtin/text.rs index fe7d419..51a6d69 100644 --- a/hui/src/element/builtin/text.rs +++ b/hui/src/element/builtin/text.rs @@ -1,3 +1,5 @@ +//! simple text element, renders a string of text + use std::borrow::Cow; use derive_setters::Setters; use glam::{vec2, Vec4}; @@ -17,17 +19,28 @@ use crate::{ // Constant(u8), // } +/// Simple text element, renders a string of text #[derive(Setters)] #[setters(prefix = "with_")] pub struct Text { + /// Text to render #[setters(into)] pub text: Cow<'static, str>, + + /// Size of the text element #[setters(into)] pub size: Size2d, + + /// Color of the text #[setters(into)] pub color: Vec4, + + /// Font to use for rendering the text\ + /// If set to `None` either currently selected font or the default font will be used #[setters(into)] pub font: Option, + + /// Size of the text, in points (these are not pixels) pub text_size: u16, } diff --git a/hui/src/element/builtin/transformer.rs b/hui/src/element/builtin/transformer.rs index bff9321..be27a5b 100644 --- a/hui/src/element/builtin/transformer.rs +++ b/hui/src/element/builtin/transformer.rs @@ -1,3 +1,5 @@ +//! wrapper that allows applying various transformations to an element, such as translation, rotation, or scaling + use glam::{Affine2, Vec2}; use crate::{ draw::UiDrawCommand, element::{MeasureContext, ProcessContext, UiElement}, measure::Response @@ -8,6 +10,8 @@ pub struct Transformer { pub element: Box, } +/// Wrapper that allows applying various transformations to an element, such as translation, rotation, or scaling\ +/// Use sparingly, as this is an experimental feature and may not work as expected\ impl Transformer { pub fn new(element: Box) -> Self { Self { @@ -52,16 +56,17 @@ impl UiElement for Transformer { } } +/// Extension trait for [`UiElement`] that adds the [`transform`] method pub trait ElementTransformExt { - fn transform(self) -> Transformer; -} - -impl ElementTransformExt for T { /// Wrap the element in a [`Transformer`] /// /// This allows you to apply various transformations to the element, such as translation, rotation, or scaling\ /// Use sparingly, as this is an experimental feature and may not work as expected\ /// Transform is applied around the center of the element's bounding box. + fn transform(self) -> Transformer; +} + +impl ElementTransformExt for T { fn transform(self) -> Transformer { Transformer::new(Box::new(self)) }