Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/crates/bevy_feathers/src/rounded_corners.rs
6595 views
1
//! Mechanism for specifying which corners of a widget are rounded, used for segmented buttons
2
//! and control groups.
3
use bevy_ui::{BorderRadius, Val};
4
5
/// Allows specifying which corners are rounded and which are sharp. All rounded corners
6
/// have the same radius. Not all combinations are supported, only the ones that make
7
/// sense for a segmented buttons.
8
///
9
/// A typical use case would be a segmented button consisting of 3 individual buttons in a
10
/// row. In that case, you would have the leftmost button have rounded corners on the left,
11
/// the right-most button have rounded corners on the right, and the center button have
12
/// only sharp corners.
13
#[derive(Debug, Clone, Copy, Default, PartialEq)]
14
pub enum RoundedCorners {
15
/// No corners are rounded.
16
None,
17
#[default]
18
/// All corners are rounded.
19
All,
20
/// Top-left corner is rounded.
21
TopLeft,
22
/// Top-right corner is rounded.
23
TopRight,
24
/// Bottom-right corner is rounded.
25
BottomRight,
26
/// Bottom-left corner is rounded.
27
BottomLeft,
28
/// Top corners are rounded.
29
Top,
30
/// Right corners are rounded.
31
Right,
32
/// Bottom corners are rounded.
33
Bottom,
34
/// Left corners are rounded.
35
Left,
36
}
37
38
impl RoundedCorners {
39
/// Convert the `RoundedCorners` to a `BorderRadius` for use in a `Node`.
40
pub fn to_border_radius(&self, radius: f32) -> BorderRadius {
41
let radius = Val::Px(radius);
42
let zero = Val::ZERO;
43
match self {
44
RoundedCorners::None => BorderRadius::all(zero),
45
RoundedCorners::All => BorderRadius::all(radius),
46
RoundedCorners::TopLeft => BorderRadius {
47
top_left: radius,
48
top_right: zero,
49
bottom_right: zero,
50
bottom_left: zero,
51
},
52
RoundedCorners::TopRight => BorderRadius {
53
top_left: zero,
54
top_right: radius,
55
bottom_right: zero,
56
bottom_left: zero,
57
},
58
RoundedCorners::BottomRight => BorderRadius {
59
top_left: zero,
60
top_right: zero,
61
bottom_right: radius,
62
bottom_left: zero,
63
},
64
RoundedCorners::BottomLeft => BorderRadius {
65
top_left: zero,
66
top_right: zero,
67
bottom_right: zero,
68
bottom_left: radius,
69
},
70
RoundedCorners::Top => BorderRadius {
71
top_left: radius,
72
top_right: radius,
73
bottom_right: zero,
74
bottom_left: zero,
75
},
76
RoundedCorners::Right => BorderRadius {
77
top_left: zero,
78
top_right: radius,
79
bottom_right: radius,
80
bottom_left: zero,
81
},
82
RoundedCorners::Bottom => BorderRadius {
83
top_left: zero,
84
top_right: zero,
85
bottom_right: radius,
86
bottom_left: radius,
87
},
88
RoundedCorners::Left => BorderRadius {
89
top_left: radius,
90
top_right: zero,
91
bottom_right: zero,
92
bottom_left: radius,
93
},
94
}
95
}
96
}
97
98