sequoia_view/
styleable.rs1use sequoia_core::{Color, Edges};
2use sequoia_style::BoxStyle;
3
4pub trait Styleable: Sized {
5 fn fill_width(self) -> Self;
6 fn fill_height(self) -> Self;
7 fn fill_size(self) -> Self {
8 self.fill_width().fill_height()
9 }
10 fn fit(self) -> Self;
11 fn hit_testable(self, on: bool) -> Self;
12 fn padding(self, padding: impl Into<Edges>) -> Self;
13 fn padding_xy(self, x: f32, y: f32) -> Self {
14 self.padding(Edges::xy(x, y))
15 }
16}
17
18pub trait Decoratable: Sized {
19 fn background(self, color: Color) -> Self;
20 fn border(self, width: f32, color: Color) -> Self;
21 fn radius(self, radius: f32) -> Self;
22 fn box_style(self, style: BoxStyle) -> Self;
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn traits_are_object_safe_contracts() {
31 fn assert_styleable<T: Styleable>() {}
32 fn assert_decoratable<T: Decoratable>() {}
33 assert_styleable::<crate::views::Row>();
34 assert_styleable::<crate::views::Column>();
35 assert_decoratable::<crate::views::Row>();
36 assert_decoratable::<crate::views::Column>();
37 }
38}