bevy/crates/bevy_ui/src
Dawid Piotrowski 9066d51420 Utility methods for Val (#6134)
# Objective

Adds a better interface for performing mathematical operations with UI unit `Val`. Fixes #6080.

## Solution

- Added `try_add` and `try_sub` methods to Val.
- Removed the `Add` and `AddAssign` impls for `Val` that introduced unintuitive and bug-prone behaviour.
- As a consequence of the prior,  ~~changed the `Add` and `Sub` impls for the `Size` struct to take a `(Val, Val)` instead of `Vec2`~~ deleted the `Add` and `Sub` impls for the `Size` struct
- Added a `From<(Val, Val)>` impl for the `Size` struct
- Added `evaluate(size: f32)` method that converts from `Val::Percent` to `Val::Px`.
- Added `try_add_with_size` and `try_sub_with_size` methods to `Val`, which evaluate `Val::Percent` values into `Val::Px` values before adding.

---

## Migration Guide

Instead of using the + and - operators, perform calculations on `Val`s using the new `try_add` and `try_sub` methods. Multiplication and division remained unchanged. Also, when adding or subtracting from `Size`, ~~use a `Val` tuple instead of `Vec2`~~ perform the addition on `width` and `height` separately.


Co-authored-by: Dawid Piotrowski <41804418+Pietrek14@users.noreply.github.com>
2022-10-24 14:33:46 +00:00
..
flex Clarify bevy::ui::Node field and documentation (#5995) 2022-10-17 13:27:24 +00:00
render Clarify bevy::ui::Node field and documentation (#5995) 2022-10-17 13:27:24 +00:00
widget Fixes incorrect glyph positioning for text2d (#6273) 2022-10-18 13:28:34 +00:00
entity.rs Make the default background color of NodeBundle transparent (#6211) 2022-10-09 21:03:05 +00:00
focus.rs Clarify bevy::ui::Node field and documentation (#5995) 2022-10-17 13:27:24 +00:00
geometry.rs Utility methods for Val (#6134) 2022-10-24 14:33:46 +00:00
lib.rs Change UI coordinate system to have origin at top left corner (#6000) 2022-10-11 12:51:44 +00:00
ui_node.rs Utility methods for Val (#6134) 2022-10-24 14:33:46 +00:00
update.rs Clarify bevy::ui::Node field and documentation (#5995) 2022-10-17 13:27:24 +00:00