hUI/hui/src/measure.rs

42 lines
1.2 KiB
Rust
Raw Normal View History

2024-02-27 13:31:12 -06:00
//! element measurement, hints and responses
2024-02-17 14:43:46 -06:00
use glam::Vec2;
2024-03-21 17:22:40 -05:00
use crate::rect::Rect;
2024-02-17 14:43:46 -06:00
// #[non_exhaustive]
2024-02-17 14:43:46 -06:00
#[derive(Default)]
pub struct Hints {
pub inner_content_size: Option<Vec2>,
pub inner_content_size_cache: Option<Vec<Vec2>>,
}
#[derive(Default)]
pub struct Response {
2024-03-06 10:19:35 -06:00
/// Computed size of the element
2024-02-17 14:43:46 -06:00
pub size: Vec2,
2024-03-06 10:19:35 -06:00
/// Hints for the layout system, can be used to optimize the layout engine.\
/// These will never cause the UI to be rendered differently (assuming the values are correct)
2024-02-17 14:43:46 -06:00
pub hints: Hints,
2024-03-06 10:19:35 -06:00
/// Arbitrary user data, can be used to pass data (for example, cache) between measure and process stages
2024-02-17 14:43:46 -06:00
pub user_data: Option<Box<dyn std::any::Any>>,
2024-03-06 10:19:35 -06:00
/// If true, the element should always cause the content to wrap to the next line\
/// (the element itself gets wrapped to the next line too)
///
/// You should almost never set this, and the exact behavior may change in the future
2024-03-11 19:38:11 -05:00
///
/// Currently, this forces wrapping even if Container::wrap is set to false
2024-03-06 10:19:35 -06:00
pub should_wrap: bool,
2024-02-17 14:43:46 -06:00
}
2024-03-11 14:48:39 -05:00
impl Response {
pub fn rect(&self, position: Vec2) -> Rect {
Rect {
position,
size: self.size,
}
}
}