Skip to main content

cranpose_ui/modifier/
border.rs

1use super::{Brush, Modifier, RoundedCornerShape, inspector_metadata};
2use crate::modifier_nodes::BorderElement;
3
4impl Modifier {
5    /// Strokes the edge of `shape` in `brush`, `width` wide, over the content
6    /// and inside the node's bounds, as Compose's
7    /// `Modifier.border(width, brush, shape)` does; a colour paints as a
8    /// solid brush. `RoundedCornerShape::uniform(0.0)` borders a rectangle.
9    ///
10    /// Example: `Modifier::empty().border(1.0, Color::BLACK, RoundedCornerShape::uniform(6.0))`
11    pub fn border(self, width: f32, brush: impl Into<Brush>, shape: RoundedCornerShape) -> Self {
12        let brush = brush.into();
13        let metadata = inspector_metadata("border", |info| {
14            info.add_property("width", format!("{width}"));
15            info.add_property("brush", format!("{brush:?}"));
16        });
17        let modifier = Self::with_element(BorderElement::new(width, brush, shape))
18            .with_inspector_metadata(metadata);
19        self.then(modifier)
20    }
21}
22
23#[cfg(test)]
24#[path = "tests/border_tests.rs"]
25mod tests;