From 4f2666565ee39fafe653c5a377b22521d308196a Mon Sep 17 00:00:00 2001 From: IDEDARY Date: Mon, 3 Jun 2024 22:03:41 +0200 Subject: [PATCH] added some text to units --- docs/src/advanced/units.md | 47 +++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/docs/src/advanced/units.md b/docs/src/advanced/units.md index ce47869..80613f9 100644 --- a/docs/src/advanced/units.md +++ b/docs/src/advanced/units.md @@ -1,3 +1,48 @@ # Units -*Coming soon...* \ No newline at end of file +Lunex features 9 different UI units, which are used as arguments for `UiValue`. The `T` is expected to be `f32`, `Vec2`, `Vec3` or `Vec4`. They are used in layout functions where `impl Into>` is specified as argument. + +* `Ab` - Stands for absolute, usually `Ab(1)` = **1px** +* `Rl` - Stands for relative, it means `Rl(1.0)` == **1%** +* `Rw` - Stands for relative width, it means `Rw(1.0)` == **1%w**, but when used in *height* field, it will use *width* as source +* `Rh` - Stands for relative height, it means `Rh(1.0)` == **1%h**, but when used in *width* field, it will use *height* as source +* `Em` - Stands for size of symbol M, it means `Em(1.0)` == **1em**, so size **16px** if font size is **16px** +* `Sp` - Stands for remaining space, it's used as proportional ratio between margins, to replace alignment and justification. Only used by `Div` +* `Vp` - Stands for viewport, it means `Vp(1.0)` == **1v%** of the `UiTree` original size +* `Vw` - Stands for viewport width, it means `Vw(1.0)` == **1v%w** of the `UiTree` original size, but when used in *height* field, it will use *width* as source +* `Vh` - Stands for viewport height, it means `Vh(1.0)` == **1v%h** of the `UiTree` original size, but when used in *width* field, it will use *height* as source + +## Basic Operations + +All unit types implement basic mathematical operations: + +```rust +let a: Ab = Ab(4.0) + Ab(6.0); // -> 10px +let b: Ab = Ab(4.0) * 2.0; // -> 8px +``` + +You can also combine different unit types: + +```rust +let a: UiValue = Ab(4.0) + Rl(6.0); // -> 4px + 6% +``` + +If a unit is unspecified, the `f32` value is considered to be in `Ab` unit: + +```rust +let a: Ab = 5.0.into(); // -> 5px +``` + +## Vector Definitions + +You can easily define vectors using these units: + +```rust +let a: UiValue = Ab(10.0).into(); // -> [10px, 10px] +let b: UiValue = Ab((10.0, 15.0)).into(); // -> [10px, 15px] +let c: UiValue = (Ab(10.0), Rl(5.0)).into(); // -> [10px, 5%] +``` + +Works for larger vectors like `Vec3` and `Vec4` the same. + +If you put them as arguments to `impl Into>`, you don't have to call `.into()`.