Skip to main content

cranpose_ui/modifier/
weight.rs

1use super::{Modifier, inspector_metadata};
2use crate::modifier_nodes::WeightElement;
3
4impl Modifier {
5    /// Gives this child a share of the space that the unweighted children leave on the main axis of
6    /// a `Row` or `Column`, in proportion to `weight`. The child fills its share. Compose's
7    /// `Modifier.weight`.
8    pub fn weight(self, weight: f32) -> Self {
9        self.weight_with_fill(weight, true)
10    }
11
12    /// Like [`Self::weight`]. With `fill` set to false the child may be smaller than its share.
13    pub fn weight_with_fill(self, weight: f32, fill: bool) -> Self {
14        let modifier = Self::with_element(WeightElement::new(weight, fill))
15            .with_inspector_metadata(inspector_metadata("weight", move |info| {
16                info.add_property("weight", weight.to_string());
17                info.add_property("fill", fill.to_string());
18            }));
19        self.then(modifier)
20    }
21
22    /// Same as [`Self::weight_with_fill`], for a child of a `Column`.
23    #[expect(non_snake_case)]
24    pub fn columnWeight(self, weight: f32, fill: bool) -> Self {
25        self.weight_with_fill(weight, fill)
26    }
27
28    /// Same as [`Self::weight_with_fill`], for a child of a `Row`.
29    #[expect(non_snake_case)]
30    pub fn rowWeight(self, weight: f32, fill: bool) -> Self {
31        self.weight_with_fill(weight, fill)
32    }
33}