bevy/pipelined/bevy_ui2/src/anchors.rs
davier 25b62f9577 Port bevy_ui to pipelined-rendering (#2653)
# Objective

Port bevy_ui to pipelined-rendering (see #2535 )

## Solution

I did some changes during the port:
- [X] separate color from the texture asset (as suggested [here](https://discord.com/channels/691052431525675048/743663924229963868/874353914525413406))
- [X] ~give the vertex shader a per-instance buffer instead of per-vertex buffer~ (incompatible with batching)

Remaining features to implement to reach parity with the old renderer:
- [x] textures
- [X] TextBundle

I'd also like to add these features, but they need some design discussion:
- [x] batching
- [ ] separate opaque and transparent phases
- [ ] multiple windows
- [ ] texture atlases
- [ ] (maybe) clipping
2021-12-10 22:21:23 +00:00

46 lines
1.6 KiB
Rust

#[derive(Debug, Clone)]
pub struct Anchors {
pub left: f32,
pub right: f32,
pub bottom: f32,
pub top: f32,
}
impl Anchors {
pub const BOTTOM_FULL: Anchors = Anchors::new(0.0, 1.0, 0.0, 0.0);
pub const BOTTOM_LEFT: Anchors = Anchors::new(0.0, 0.0, 0.0, 0.0);
pub const BOTTOM_RIGHT: Anchors = Anchors::new(1.0, 1.0, 0.0, 0.0);
pub const CENTER: Anchors = Anchors::new(0.5, 0.5, 0.5, 0.5);
pub const CENTER_BOTTOM: Anchors = Anchors::new(0.5, 0.5, 0.0, 0.0);
pub const CENTER_FULL_HORIZONTAL: Anchors = Anchors::new(0.0, 1.0, 0.5, 0.5);
pub const CENTER_FULL_VERTICAL: Anchors = Anchors::new(0.5, 0.5, 0.0, 1.0);
pub const CENTER_LEFT: Anchors = Anchors::new(0.0, 0.0, 0.5, 0.5);
pub const CENTER_RIGHT: Anchors = Anchors::new(1.0, 1.0, 0.5, 0.5);
pub const CENTER_TOP: Anchors = Anchors::new(0.5, 0.5, 1.0, 1.0);
pub const FULL: Anchors = Anchors::new(0.0, 1.0, 0.0, 1.0);
pub const LEFT_FULL: Anchors = Anchors::new(0.0, 0.0, 0.0, 1.0);
pub const RIGHT_FULL: Anchors = Anchors::new(1.0, 1.0, 0.0, 1.0);
pub const TOP_FULL: Anchors = Anchors::new(0.0, 1.0, 1.0, 1.0);
pub const TOP_LEFT: Anchors = Anchors::new(0.0, 0.0, 1.0, 1.0);
pub const TOP_RIGHT: Anchors = Anchors::new(1.0, 1.0, 1.0, 1.0);
pub const fn new(left: f32, right: f32, bottom: f32, top: f32) -> Self {
Anchors {
left,
right,
bottom,
top,
}
}
}
impl Default for Anchors {
fn default() -> Self {
Anchors {
left: 0.0,
right: 0.0,
bottom: 0.0,
top: 0.0,
}
}
}