Skip to content

Commit 2e7d084

Browse files
oceantumetygyh
authored andcommitted
Add Border and BorderRadius components to bevy_ui
1 parent 08ce579 commit 2e7d084

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;
@@ -54,6 +54,10 @@ pub struct NodeBundle {
5454
pub view_visibility: ViewVisibility,
5555
/// Indicates the depth at which the node should appear in the UI
5656
pub z_index: ZIndex,
57+
/// Describes the border radius of the node
58+
pub border_radius: BorderRadius,
59+
/// Describes the visual properties of the node's border
60+
pub border: Border,
5761
}
5862

5963
impl Default for NodeBundle {
@@ -71,6 +75,8 @@ impl Default for NodeBundle {
7175
inherited_visibility: Default::default(),
7276
view_visibility: Default::default(),
7377
z_index: Default::default(),
78+
border_radius: Default::default(),
79+
border: Default::default(),
7480
}
7581
}
7682
}
@@ -119,6 +125,10 @@ pub struct ImageBundle {
119125
pub view_visibility: ViewVisibility,
120126
/// Indicates the depth at which the node should appear in the UI
121127
pub z_index: ZIndex,
128+
/// Describes the border radius of the node
129+
pub border_radius: BorderRadius,
130+
/// Describes the visual properties of the node's border
131+
pub border: Border,
122132
}
123133

124134
/// A UI node that is a texture atlas sprite
@@ -390,6 +400,10 @@ pub struct MaterialNodeBundle<M: UiMaterial> {
390400
pub view_visibility: ViewVisibility,
391401
/// Indicates the depth at which the node should appear in the UI
392402
pub z_index: ZIndex,
403+
/// Describes the border radius of the node
404+
pub border_radius: BorderRadius,
405+
/// Describes the visual properties of the node's border
406+
pub border: Border,
393407
}
394408

395409
impl<M: UiMaterial> Default for MaterialNodeBundle<M> {
@@ -405,6 +419,8 @@ impl<M: UiMaterial> Default for MaterialNodeBundle<M> {
405419
inherited_visibility: Default::default(),
406420
view_visibility: Default::default(),
407421
z_index: Default::default(),
422+
border_radius: Default::default(),
423+
border: Default::default(),
408424
}
409425
}
410426
}

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)