@@ -89,6 +89,7 @@ impl StylePropValue for MinTrackSizingFunction {}
89
89
impl StylePropValue for MaxTrackSizingFunction { }
90
90
impl < T : StylePropValue , M : StylePropValue > StylePropValue for MinMax < T , M > { }
91
91
impl < T : StylePropValue > StylePropValue for Line < T > { }
92
+ impl StylePropValue for taffy:: GridAutoFlow { }
92
93
impl StylePropValue for GridPlacement { }
93
94
impl StylePropValue for CursorStyle { }
94
95
impl StylePropValue for BoxShadow {
@@ -1195,7 +1196,7 @@ impl Style {
1195
1196
self
1196
1197
}
1197
1198
1198
- fn get_nested_map ( & self , key : StyleKey ) -> Option < Style > {
1199
+ pub ( crate ) fn get_nested_map ( & self , key : StyleKey ) -> Option < Style > {
1199
1200
self . map
1200
1201
. get ( & key)
1201
1202
. map ( |map| map. downcast_ref :: < Style > ( ) . unwrap ( ) . clone ( ) )
@@ -1355,6 +1356,10 @@ impl Style {
1355
1356
pub fn apply_overriding_styles ( self , overrides : impl Iterator < Item = Style > ) -> Style {
1356
1357
overrides. fold ( self , |acc, x| acc. apply ( x) )
1357
1358
}
1359
+
1360
+ pub ( crate ) fn clear ( & mut self ) {
1361
+ self . map . clear ( ) ;
1362
+ }
1358
1363
}
1359
1364
1360
1365
impl Debug for Style {
@@ -1636,6 +1641,7 @@ define_builtin_props!(
1636
1641
GridTemplateColumns grid_template_columns: Vec <TrackSizingFunction > { } = Vec :: new( ) ,
1637
1642
GridAutoRows grid_auto_rows: Vec <MinMax <MinTrackSizingFunction , MaxTrackSizingFunction >> { } = Vec :: new( ) ,
1638
1643
GridAutoColumns grid_auto_columns: Vec <MinMax <MinTrackSizingFunction , MaxTrackSizingFunction >> { } = Vec :: new( ) ,
1644
+ GridAutoFlow grid_auto_flow: taffy:: GridAutoFlow { } = taffy:: GridAutoFlow :: Row ,
1639
1645
GridRow grid_row: Line <GridPlacement > { } = Line :: default ( ) ,
1640
1646
GridColumn grid_column: Line <GridPlacement > { } = Line :: default ( ) ,
1641
1647
AlignSelf align_self: Option <AlignItems > { } = None ,
@@ -1878,6 +1884,30 @@ impl Style {
1878
1884
self
1879
1885
}
1880
1886
1887
+ /// Applies a `CustomStyle` type to the `CustomStyle`'s associated style class.
1888
+ ///
1889
+ /// For example: if the `CustomStyle` you use is `DropdownCustomStyle` then it
1890
+ /// will apply the custom style to that custom style type's associated style class
1891
+ /// which, in this example, is `DropdownClass`.
1892
+ ///
1893
+ /// This is especially useful when building a stylesheet or targeting a child view.
1894
+ ///
1895
+ /// # Examples
1896
+ /// ```
1897
+ /// // In a style sheet or on a parent view
1898
+ /// use floem::prelude::*;
1899
+ /// use floem::style::Style;
1900
+ /// Style::new().custom_style_class(|s: dropdown::DropdownCustomStyle| s.close_on_accept(false));
1901
+ /// // This property is now set on the `DropdownClass` class and will be applied to any dropdowns that are children of this view.
1902
+ /// ```
1903
+ ///
1904
+ /// See also: [`Style::custom`](Self::custom) and [`Style::apply_custom`](Self::apply_custom).
1905
+ pub fn custom_style_class < CS : CustomStyle > ( mut self , style : impl FnOnce ( CS ) -> CS ) -> Self {
1906
+ let over = style ( CS :: default ( ) ) ;
1907
+ self . set_class ( CS :: StyleClass :: class_ref ( ) , over. into ( ) ) ;
1908
+ self
1909
+ }
1910
+
1881
1911
pub fn width_full ( self ) -> Self {
1882
1912
self . width_pct ( 100.0 )
1883
1913
}
@@ -2362,6 +2392,28 @@ impl Style {
2362
2392
}
2363
2393
}
2364
2394
2395
+ /// Applies a `CustomStyle` type into this style.
2396
+ ///
2397
+ /// # Examples
2398
+ /// ```
2399
+ /// use floem::prelude::*;
2400
+ /// text("test").style(|s| s.custom(|s: LabelCustomStyle| s.selectable(false)));
2401
+ /// ```
2402
+ ///
2403
+ /// See also: [`apply_custom`](Self::apply_custom), [`custom_style_class`](Self::custom_style_class)
2404
+ pub fn custom < CS : CustomStyle > ( self , custom : impl FnOnce ( CS ) -> CS ) -> Self {
2405
+ self . apply ( custom ( CS :: default ( ) ) . into ( ) )
2406
+ }
2407
+
2408
+ /// Applies a `CustomStyle` type into this style.
2409
+ ///
2410
+ /// # Examples
2411
+ /// ```
2412
+ /// use floem::prelude::*;
2413
+ /// text("test").style(|s| s.apply_custom(LabelCustomStyle::new().selectable(false)));
2414
+ /// ```
2415
+ ///
2416
+ /// See also: [`custom`](Self::custom), [`custom_style_class`](Self::custom_style_class)
2365
2417
pub fn apply_custom < CS : Into < Style > > ( self , custom_style : CS ) -> Self {
2366
2418
self . apply ( custom_style. into ( ) )
2367
2419
}
@@ -2455,12 +2507,22 @@ impl Style {
2455
2507
grid_column : style. grid_column ( ) ,
2456
2508
grid_auto_rows : style. grid_auto_rows ( ) ,
2457
2509
grid_auto_columns : style. grid_auto_columns ( ) ,
2510
+ grid_auto_flow : style. grid_auto_flow ( ) ,
2458
2511
..Default :: default ( )
2459
2512
}
2460
2513
}
2461
2514
}
2462
2515
2463
2516
pub trait CustomStyle : Default + Clone + Into < Style > + From < Style > {
2517
+ type StyleClass : StyleClass ;
2518
+
2519
+ /// Get access to a normal style
2520
+ fn style ( self , style : impl FnOnce ( Style ) -> Style ) -> Self {
2521
+ let self_style = self . into ( ) ;
2522
+ let new = style ( self_style) ;
2523
+ new. into ( )
2524
+ }
2525
+
2464
2526
fn hover ( self , style : impl FnOnce ( Self ) -> Self ) -> Self {
2465
2527
let self_style: Style = self . into ( ) ;
2466
2528
let new = self_style. selector ( StyleSelector :: Hover , |_| style ( Self :: default ( ) ) . into ( ) ) ;
@@ -2510,7 +2572,6 @@ pub trait CustomStyle: Default + Clone + Into<Style> + From<Style> {
2510
2572
self_style. into ( )
2511
2573
}
2512
2574
}
2513
- impl < T > CustomStyle for T where T : Default + Clone + Into < Style > + From < Style > { }
2514
2575
2515
2576
pub trait CustomStylable < S : CustomStyle + ' static > : IntoView < V = Self :: DV > + Sized {
2516
2577
type DV : View ;
0 commit comments