Improve the 'Val` doc comments (#8134)

# Objective

Add comments explaining:
* That `Val::Px` is a value in logical pixels
* That `Val::Percent` is based on the length of its parent along a
specific axis.
* How the layout algorithm determines which axis the percentage should
be based on.
This commit is contained in:
ickshonpe 2023-03-20 22:51:24 +00:00 committed by GitHub
parent 7b38de0a64
commit 3b51e1c8d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,15 +57,29 @@ impl Default for Node {
} }
} }
/// An enum that describes possible types of value in flexbox layout options /// Represents the possible value types for layout properties.
///
/// This enum allows specifying values for various [`Style`] properties in different units,
/// such as logical pixels, percentages, or automatically determined values.
#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)] #[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize, Reflect)]
#[reflect(PartialEq, Serialize, Deserialize)] #[reflect(PartialEq, Serialize, Deserialize)]
pub enum Val { pub enum Val {
/// Automatically determine this value /// Automatically determine the value based on the context and other `Style` properties.
Auto, Auto,
/// Set this value in pixels /// Set this value in logical pixels.
Px(f32), Px(f32),
/// Set this value in percent /// Set the value as a percentage of its parent node's length along a specific axis.
///
/// If the UI node has no parent, the percentage is calculated based on the window's length
/// along the corresponding axis.
///
/// The chosen axis depends on the `Style` field set:
/// * For `flex_basis`, the percentage is relative to the main-axis length determined by the `flex_direction`.
/// * For `gap`, `min_size`, `size`, and `max_size`:
/// - `width` is relative to the parent's width.
/// - `height` is relative to the parent's height.
/// * For `margin`, `padding`, and `border` values: the percentage is relative to the parent node's width.
/// * For positions, `left` and `right` are relative to the parent's width, while `bottom` and `top` are relative to the parent's height.
Percent(f32), Percent(f32),
} }