
# Objective This PR implements the `overflow` style property in `bevy_ui`. When set to `Overflow::Hidden`, the children of that node are clipped so that overflowing parts are not rendered. This is an important building block for UI widgets. ## Solution Clipping is done on the CPU so that it does not break batching. The clip regions update was implemented as a separate system for clarity, but it could be merged with the other UI systems to avoid doing an additional tree traversal. (I don't think it's important until we fix the layout performance issues though). A scrolling list was added to the `ui_pipelined` example to showcase `Overflow::Hidden`. For the sake of simplicity, it can only be scrolled with a mouse.
28 lines
614 B
Rust
28 lines
614 B
Rust
use bevy_math::Vec2;
|
|
use bevy_reflect::Reflect;
|
|
|
|
/// A rectangle defined by two points. There is no defined origin, so 0,0 could be anywhere
|
|
/// (top-left, bottom-left, etc)
|
|
#[repr(C)]
|
|
#[derive(Default, Clone, Copy, Debug, Reflect)]
|
|
pub struct Rect {
|
|
/// The beginning point of the rect
|
|
pub min: Vec2,
|
|
/// The ending point of the rect
|
|
pub max: Vec2,
|
|
}
|
|
|
|
impl Rect {
|
|
pub fn width(&self) -> f32 {
|
|
self.max.x - self.min.x
|
|
}
|
|
|
|
pub fn height(&self) -> f32 {
|
|
self.max.y - self.min.y
|
|
}
|
|
|
|
pub fn size(&self) -> Vec2 {
|
|
Vec2::new(self.width(), self.height())
|
|
}
|
|
}
|