Skip to main content

ferroui_view/
extras.rs

1//! Builder methods for what the generator cannot see: values of classes that
2//! are not registered properties.
3
4use crate::builder::El;
5use ferroui_base::{ObjectType, Upcast};
6use ferroui_controls::{ColumnDefinitions, Grid, RowDefinitions};
7
8/// The rows and columns of a grid, in the text form XAML takes
9/// (`"Auto,*,2*,40"`).
10pub trait GridDefinitions {
11    /// `Grid.RowDefinitions`.
12    fn row_definitions(self, rows: &str) -> Self;
13    /// `Grid.ColumnDefinitions`.
14    fn column_definitions(self, columns: &str) -> Self;
15}
16
17impl<T: ObjectType + Upcast<Grid>> GridDefinitions for El<T> {
18    fn row_definitions(self, rows: &str) -> Self {
19        let rows = RowDefinitions::parse(rows).unwrap_or_else(|_| panic!("`{rows}` are not row definitions"));
20        self.with(move |grid| {
21            let grid: &Ref<Grid> = grid.upcast_ref();
22            grid.set_row_definitions(rows.clone());
23        })
24    }
25
26    fn column_definitions(self, columns: &str) -> Self {
27        let columns =
28            ColumnDefinitions::parse(columns).unwrap_or_else(|_| panic!("`{columns}` are not column definitions"));
29        self.with(move |grid| {
30            let grid: &Ref<Grid> = grid.upcast_ref();
31            grid.set_column_definitions(columns.clone());
32        })
33    }
34}
35
36use ferroui_base::Ref;