mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-22 07:08:42 -06:00
update docs
This commit is contained in:
parent
ac723bad3f
commit
392fed5798
|
@ -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 std::any::Any;
|
||||||
use crate::{
|
use crate::{
|
||||||
draw::UiDrawCommandList,
|
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 {
|
pub trait UiElementExt: UiElement {
|
||||||
/// Add element as a child/nested element.
|
/// Add element as a child/nested element.
|
||||||
fn add_child(self, ui: &mut ElementList);
|
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) {
|
fn add_child(self, ui: &mut ElementList) {
|
||||||
ui.add(self)
|
ui.add(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_root(self, ui: &mut UiInstance, max_size: glam::Vec2) {
|
fn add_root(self, ui: &mut UiInstance, max_size: glam::Vec2) {
|
||||||
ui.add(self, max_size);
|
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 derive_setters::Setters;
|
||||||
use glam::{Vec2, vec2};
|
use glam::{Vec2, vec2};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -14,26 +16,42 @@ use crate::{
|
||||||
// pub width: f32,
|
// pub width: f32,
|
||||||
// }
|
// }
|
||||||
|
|
||||||
///XXX: add Order/Direction::Forward/Reverse or sth?
|
//XXX: add Order/Direction::Forward/Reverse or sth?
|
||||||
//TODO: clip children flag
|
//TODO: clip children flag
|
||||||
//TODO: borders
|
//TODO: borders
|
||||||
//TODO: min/max size
|
//TODO: min/max size
|
||||||
|
|
||||||
|
/// A container element that can hold and layout multiple children elements
|
||||||
#[derive(Setters)]
|
#[derive(Setters)]
|
||||||
#[setters(prefix = "with_")]
|
#[setters(prefix = "with_")]
|
||||||
pub struct Container {
|
pub struct Container {
|
||||||
|
/// Size of the container
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub size: Size2d,
|
pub size: Size2d,
|
||||||
|
|
||||||
|
/// Layout direction (horizontal/vertical)
|
||||||
pub direction: UiDirection,
|
pub direction: UiDirection,
|
||||||
|
|
||||||
|
/// Gap between children elements
|
||||||
pub gap: f32,
|
pub gap: f32,
|
||||||
|
|
||||||
|
/// Padding inside the container (distance from the edges to the children elements)
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub padding: Sides<f32>,
|
pub padding: Sides<f32>,
|
||||||
|
|
||||||
|
/// Alignment of the children elements on X and Y axis
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub align: Alignment2d,
|
pub align: Alignment2d,
|
||||||
|
|
||||||
|
/// Background color of the container
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub background: RectBackground,
|
pub background: RectBackground,
|
||||||
|
|
||||||
|
/// Corner radius of the background rectangle
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub corner_radius: Corners<f32>,
|
pub corner_radius: Corners<f32>,
|
||||||
|
|
||||||
|
/// List of children elements
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
pub children: ElementList,
|
pub children: ElementList,
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,22 @@ use crate::{
|
||||||
#[derive(Debug, Clone, Copy, Setters)]
|
#[derive(Debug, Clone, Copy, Setters)]
|
||||||
#[setters(prefix = "with_")]
|
#[setters(prefix = "with_")]
|
||||||
pub struct ProgressBar {
|
pub struct ProgressBar {
|
||||||
|
/// Current progress, should be in the range 0.0..=1.0
|
||||||
pub value: f32,
|
pub value: f32,
|
||||||
|
|
||||||
|
/// Size of the progress bar element
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub size: Size2d,
|
pub size: Size2d,
|
||||||
|
|
||||||
|
/// Foreground (bar) color
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub foreground: RectBackground,
|
pub foreground: RectBackground,
|
||||||
|
|
||||||
|
/// Background color
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub background: RectBackground,
|
pub background: RectBackground,
|
||||||
|
|
||||||
|
/// Corner radius of the progress bar
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub corner_radius: Corners<f32>,
|
pub corner_radius: Corners<f32>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
//! simple text element, renders a string of text
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use derive_setters::Setters;
|
use derive_setters::Setters;
|
||||||
use glam::{vec2, Vec4};
|
use glam::{vec2, Vec4};
|
||||||
|
@ -17,17 +19,28 @@ use crate::{
|
||||||
// Constant(u8),
|
// Constant(u8),
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
/// Simple text element, renders a string of text
|
||||||
#[derive(Setters)]
|
#[derive(Setters)]
|
||||||
#[setters(prefix = "with_")]
|
#[setters(prefix = "with_")]
|
||||||
pub struct Text {
|
pub struct Text {
|
||||||
|
/// Text to render
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub text: Cow<'static, str>,
|
pub text: Cow<'static, str>,
|
||||||
|
|
||||||
|
/// Size of the text element
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub size: Size2d,
|
pub size: Size2d,
|
||||||
|
|
||||||
|
/// Color of the text
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub color: Vec4,
|
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)]
|
#[setters(into)]
|
||||||
pub font: Option<FontHandle>,
|
pub font: Option<FontHandle>,
|
||||||
|
|
||||||
|
/// Size of the text, in points (these are not pixels)
|
||||||
pub text_size: u16,
|
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 glam::{Affine2, Vec2};
|
||||||
use crate::{
|
use crate::{
|
||||||
draw::UiDrawCommand, element::{MeasureContext, ProcessContext, UiElement}, measure::Response
|
draw::UiDrawCommand, element::{MeasureContext, ProcessContext, UiElement}, measure::Response
|
||||||
|
@ -8,6 +10,8 @@ pub struct Transformer {
|
||||||
pub element: Box<dyn UiElement>,
|
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 {
|
impl Transformer {
|
||||||
pub fn new(element: Box<dyn UiElement>) -> Self {
|
pub fn new(element: Box<dyn UiElement>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -52,16 +56,17 @@ impl UiElement for Transformer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extension trait for [`UiElement`] that adds the [`transform`] method
|
||||||
pub trait ElementTransformExt {
|
pub trait ElementTransformExt {
|
||||||
fn transform(self) -> Transformer;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: UiElement + 'static> ElementTransformExt for T {
|
|
||||||
/// Wrap the element in a [`Transformer`]
|
/// Wrap the element in a [`Transformer`]
|
||||||
///
|
///
|
||||||
/// This allows you to apply various transformations to the element, such as translation, rotation, or scaling\
|
/// 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\
|
/// 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.
|
/// 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 {
|
fn transform(self) -> Transformer {
|
||||||
Transformer::new(Box::new(self))
|
Transformer::new(Box::new(self))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue