Skip to content

Commit a68b9ee

Browse files
oceantumetygyh
authored andcommitted
Add Border and BorderRadius components to bevy_ui
1 parent f45450e commit a68b9ee

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

crates/bevy_ui/src/node_bundles.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
use crate::widget::TextFlags;
55
use crate::{
66
widget::{Button, UiImageSize},
7-
BackgroundColor, BorderColor, ContentSize, FocusPolicy, Interaction, Node, Style, UiImage,
8-
UiMaterial, ZIndex,
7+
BackgroundColor, Border, BorderColor, BorderRadius, ContentSize, FocusPolicy, Interaction,
8+
Node, Style, UiImage, UiMaterial, ZIndex,
99
};
1010
use bevy_asset::Handle;
1111
use bevy_ecs::bundle::Bundle;
@@ -50,6 +50,10 @@ pub struct NodeBundle {
5050
pub visibility: Visibility,
5151
/// Inherited visibility of an entity.
5252
pub inherited_visibility: InheritedVisibility,
53+
/// Describes the border radius of the node
54+
pub border_radius: BorderRadius,
55+
/// Describes the visual properties of the node's border
56+
pub border: Border,
5357
/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
5458
pub view_visibility: ViewVisibility,
5559
/// Indicates the depth at which the node should appear in the UI
@@ -70,6 +74,8 @@ impl Default for NodeBundle {
7074
visibility: Default::default(),
7175
inherited_visibility: Default::default(),
7276
view_visibility: Default::default(),
77+
border_radius: Default::default(),
78+
border: Default::default(),
7379
z_index: Default::default(),
7480
}
7581
}
@@ -115,6 +121,10 @@ pub struct ImageBundle {
115121
pub visibility: Visibility,
116122
/// Inherited visibility of an entity.
117123
pub inherited_visibility: InheritedVisibility,
124+
/// Describes the border radius of the node
125+
pub border_radius: BorderRadius,
126+
/// Describes the visual properties of the node's border
127+
pub border: Border,
118128
/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
119129
pub view_visibility: ViewVisibility,
120130
/// Indicates the depth at which the node should appear in the UI
@@ -386,6 +396,10 @@ pub struct MaterialNodeBundle<M: UiMaterial> {
386396
pub visibility: Visibility,
387397
/// Inherited visibility of an entity.
388398
pub inherited_visibility: InheritedVisibility,
399+
/// Describes the border radius of the node
400+
pub border_radius: BorderRadius,
401+
/// Describes the visual properties of the node's border
402+
pub border: Border,
389403
/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
390404
pub view_visibility: ViewVisibility,
391405
/// Indicates the depth at which the node should appear in the UI
@@ -402,6 +416,8 @@ impl<M: UiMaterial> Default for MaterialNodeBundle<M> {
402416
transform: Default::default(),
403417
global_transform: Default::default(),
404418
visibility: Default::default(),
419+
border_radius: Default::default(),
420+
border: Default::default(),
405421
inherited_visibility: Default::default(),
406422
view_visibility: Default::default(),
407423
z_index: Default::default(),

crates/bevy_ui/src/ui_node.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,3 +1917,48 @@ impl<'w, 's> DefaultUiCamera<'w, 's> {
19171917
})
19181918
}
19191919
}
1920+
1921+
/// The border radius of the node
1922+
///
1923+
/// This doesn't require a [`Border`] component
1924+
#[derive(Component, Default, Copy, Clone, Debug, Reflect)]
1925+
#[reflect(Component)]
1926+
pub struct BorderRadius {
1927+
pub top_left: f32,
1928+
pub bottom_left: f32,
1929+
pub top_right: f32,
1930+
pub bottom_right: f32,
1931+
}
1932+
1933+
impl BorderRadius {
1934+
pub fn all(border_radius: f32) -> Self {
1935+
Self {
1936+
top_left: border_radius,
1937+
bottom_left: border_radius,
1938+
top_right: border_radius,
1939+
bottom_right: border_radius,
1940+
}
1941+
}
1942+
1943+
pub fn to_array(&self) -> [f32; 4] {
1944+
[
1945+
self.top_left,
1946+
self.bottom_left,
1947+
self.top_right,
1948+
self.bottom_right,
1949+
]
1950+
}
1951+
}
1952+
1953+
/// The visual properties of the node's border
1954+
#[derive(Component, Default, Copy, Clone, Debug, Reflect)]
1955+
#[reflect(Component)]
1956+
pub struct Border {
1957+
/// The width of the border
1958+
///
1959+
/// This is different from [`Style`] border and it will not cause any displacement inside the node.
1960+
pub width: f32,
1961+
1962+
/// The color of the border
1963+
pub color: LegacyColor,
1964+
}

0 commit comments

Comments
 (0)