cranpose_ui/modifier/fill.rs
1use super::{DimensionConstraint, Modifier, inspector_metadata};
2use crate::modifier_nodes::FillElement;
3
4impl Modifier {
5 /// Have the content fill the maximum available width.
6 ///
7 /// The `fraction` parameter allows filling only a portion of the available width (0.0 to 1.0).
8 ///
9 /// Matches Kotlin: `Modifier.fillMaxWidth(fraction: Float)`
10 ///
11 /// Example: `Modifier::empty().fill_max_width()`
12 pub fn fill_max_width(self) -> Self {
13 self.fill_max_width_fraction(1.0)
14 }
15
16 /// Fill a fraction of the maximum available width.
17 ///
18 /// Example: `Modifier::empty().fill_max_width_fraction(0.5)`
19 pub fn fill_max_width_fraction(self, fraction: f32) -> Self {
20 let clamped = fraction.clamp(0.0, 1.0);
21 let modifier = Self::with_element(FillElement::width(clamped)).with_inspector_metadata(
22 inspector_metadata("fillMaxWidth", move |info| {
23 info.add_dimension("width", DimensionConstraint::Fraction(clamped));
24 }),
25 );
26 self.then(modifier)
27 }
28
29 /// Have the content fill the maximum available height.
30 ///
31 /// The `fraction` parameter allows filling only a portion of the available height (0.0 to 1.0).
32 ///
33 /// Matches Kotlin: `Modifier.fillMaxHeight(fraction: Float)`
34 ///
35 /// Example: `Modifier::empty().fill_max_height()`
36 pub fn fill_max_height(self) -> Self {
37 self.fill_max_height_fraction(1.0)
38 }
39
40 /// Fill a fraction of the maximum available height.
41 ///
42 /// Example: `Modifier::empty().fill_max_height_fraction(0.5)`
43 pub fn fill_max_height_fraction(self, fraction: f32) -> Self {
44 let clamped = fraction.clamp(0.0, 1.0);
45 let modifier = Self::with_element(FillElement::height(clamped)).with_inspector_metadata(
46 inspector_metadata("fillMaxHeight", move |info| {
47 info.add_dimension("height", DimensionConstraint::Fraction(clamped));
48 }),
49 );
50 self.then(modifier)
51 }
52
53 /// Have the content fill the maximum available size (both width and height).
54 ///
55 /// The `fraction` parameter allows filling only a portion of the available size (0.0 to 1.0).
56 ///
57 /// Matches Kotlin: `Modifier.fillMaxSize(fraction: Float)`
58 ///
59 /// Example: `Modifier::empty().fill_max_size()`
60 pub fn fill_max_size(self) -> Self {
61 self.fill_max_size_fraction(1.0)
62 }
63
64 /// Fill a fraction of the maximum available size.
65 ///
66 /// Example: `Modifier::empty().fill_max_size_fraction(0.8)`
67 pub fn fill_max_size_fraction(self, fraction: f32) -> Self {
68 let clamped = fraction.clamp(0.0, 1.0);
69 let modifier = Self::with_element(FillElement::size(clamped)).with_inspector_metadata(
70 inspector_metadata("fillMaxSize", move |info| {
71 info.add_dimension("width", DimensionConstraint::Fraction(clamped));
72 info.add_dimension("height", DimensionConstraint::Fraction(clamped));
73 }),
74 );
75 self.then(modifier)
76 }
77}