Add more remapping functions for vizia
This commit is contained in:
parent
fe5bdf3b88
commit
92908e0232
|
@ -34,6 +34,30 @@ impl ModifiersExt for Modifiers {
|
|||
}
|
||||
}
|
||||
|
||||
/// Remap a `[0, 1]` value to an x-coordinate within the current entity's bounding box. The value
|
||||
/// will be clamped to `[0, 1]` if it isn't already in that range. This ignores the border width.
|
||||
pub fn remap_current_entity_x_t(cx: &Context, t: f32) -> f32 {
|
||||
let border_width = match cx.current.get_border_width(cx) {
|
||||
vizia::Units::Pixels(x) => x,
|
||||
_ => 0.0,
|
||||
};
|
||||
let x_pos = cx.cache.get_posx(cx.current) + border_width;
|
||||
let width = cx.cache.get_width(cx.current) - (border_width * 2.0);
|
||||
x_pos + (width * t.clamp(0.0, 1.0))
|
||||
}
|
||||
|
||||
/// Remap a `[0, 1]` value to a y-coordinate within the current entity's bounding box. The value
|
||||
/// will be clamped to `[0, 1]` if it isn't already in that range. This ignores the border width.
|
||||
pub fn remap_current_entity_y_t(cx: &Context, t: f32) -> f32 {
|
||||
let border_width = match cx.current.get_border_width(cx) {
|
||||
vizia::Units::Pixels(x) => x,
|
||||
_ => 0.0,
|
||||
};
|
||||
let y_pos = cx.cache.get_posy(cx.current) + border_width;
|
||||
let height = cx.cache.get_height(cx.current) - (border_width * 2.0);
|
||||
y_pos + (height * t.clamp(0.0, 1.0))
|
||||
}
|
||||
|
||||
/// Remap an x-coordinate to a `[0, 1]` value within the current entity's bounding box. The value
|
||||
/// will be clamped to `[0, 1]` if it isn't already in that range. This ignores the border width.
|
||||
pub fn remap_current_entity_x_coordinate(cx: &Context, x_coord: f32) -> f32 {
|
||||
|
|
Loading…
Reference in a new issue