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