Expand description
A minimal 2d layout system (that works in 3d!) for bevy.
§Getting Started
First add RectrayPlugin
.
app.add_plugins(RectrayPlugin)
Then add RectrayFrame
to a parent entity.
This effectively creates a 2d rectangular space around
the local x
and y
axis of the entity’s Transform
.
commands.spawn(
SpacialBundle {
...
},
RectrayFrame::from_dimension(Vec2::new(1024., 768.)),
)
To place descendant entities inside the frame, add Transform2D
and Dimension
next to entities
with Transform
s.
commands.spawn (
Transform { .. },
Transform2D { .. },
Dimension { .. },
)
Since we only operate on Transform
, bevy_rectray
works in Transform - Transform2d - Transform
sandwich situations.
§Integration
bevy_rectray
is minimal and does not magically react to changes in bevy components.
We take in Transform2D
and Dimension
and produces Transform
and RotatedRect
.
Some of those data can come from external sources.
For example if you want to make all Sprite
s take up space of its Image
or custom_size
,
add a system like this manually:
pub fn update_sprite_dimension(
scaling_factor: Query<&Window, With<PrimaryWindow>>,
mut query: Query<(&mut Sprite, &Handle<Image>, &mut Dimension)>,
assets: Res<Assets<Image>>
) {
let scaling_factor = scaling_factor
.get_single()
.map(|x| x.scale_factor())
.unwrap_or(1.0);
query.iter_mut().for_each(|(sp, im, mut dimension)| {
dimension.0 = sp.custom_size.or_else(|| {
sp.rect.map(|rect| (rect.max - rect.min) * scaling_factor)
.or_else(|| {
assets.get(im)
.map(|x|x.size().as_vec2() * scaling_factor)
})
}).unwrap_or(Vec2::ZERO)
})
}
If you want the opposite behavior, you can update the size of a sprite from
the outputted RotatedRect::dimension
.
§Containers
Add RectrayContainerBundle
to put child items in a Layout
.
See module level documentation for details.
Modules§
- layout
- Container and Layouts for
bevy_rectray
Structs§
- Anchor
- Anchor of a sprite, this is a more concise implementation than bevy’s.
- Dimension
- Dimension of the widget, this is a suggestion and can be modified via
Layout
. - Rectray
Bundle Deprecated Bundle
forbevy_rectray
’s features, must be paired with aTransformBundle
.- Rectray
Container Bundle Deprecated Bundle
forbevy_rectray
’s features and a container, must be paired with aTransformBundle
.- Rectray
Cursor - Set
Transform2D::offset
toPrimaryWindow
’s cursor position. - Rectray
Frame - A root node that creates an area to place child entities.
- Rectray
Pickable - Make an item pickable in the
bevy_rectray
backend. - Rectray
Plugin Plugin
forbevy_rectray
.- Rectray
Transform Set SystemSet
forbevy_rectray
, runs inPostUpdate
.- Rectray
Window - Synchronize the size of
RectrayFrame
withPrimaryWindow
. - Rotated
Rect - A rotated 2D rectangle.
- Transform2D
- The 2D transform component for
bevy_rectray
.
Enums§
- Anchor
Direction - Anchor and direction for a tooltip like object.
- Interpolate
Transform - If set, changes in local
Transform
will be interpolated. - OutOf
Frame Behavior - Determines how an object reacts if out of frame.
- Sync
Dimension - Synchronize
Dimension
from or to another component likeSprite
.
Functions§
- compute_
transform_ 2d - The main computation step.