mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-12-22 12:28:19 -06:00
update docs
This commit is contained in:
parent
663f943af3
commit
9f0809c61c
|
@ -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<T: UiElement + 'static> 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);
|
||||
}
|
||||
|
|
|
@ -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<f32>,
|
||||
|
||||
/// 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<f32>,
|
||||
|
||||
/// List of children elements
|
||||
#[setters(skip)]
|
||||
pub children: ElementList,
|
||||
}
|
||||
|
|
|
@ -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<f32>,
|
||||
}
|
||||
|
|
|
@ -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<FontHandle>,
|
||||
|
||||
/// Size of the text, in points (these are not pixels)
|
||||
pub text_size: u16,
|
||||
}
|
||||
|
||||
|
|
|
@ -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<dyn UiElement>,
|
||||
}
|
||||
|
||||
/// 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<dyn UiElement>) -> 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<T: UiElement + 'static> 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<T: UiElement + 'static> ElementTransformExt for T {
|
||||
fn transform(self) -> Transformer {
|
||||
Transformer::new(Box::new(self))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue