@@ -6,6 +6,7 @@ mod segmented_button;
66
77use std:: hash:: Hash ;
88use std:: hash:: Hasher ;
9+ use std:: rc:: Rc ;
910
1011pub use self :: segmented_button:: SegmentedButton ;
1112
@@ -132,15 +133,16 @@ impl LayeredTheme for Theme {
132133 }
133134}
134135
135- #[ derive( Clone , Copy ) ]
136+ #[ derive( Default ) ]
136137pub enum Application {
138+ #[ default]
137139 Default ,
138- Custom ( fn ( & Theme ) -> application:: Appearance ) ,
140+ Custom ( Box < dyn Fn ( & Theme ) -> application:: Appearance > ) ,
139141}
140142
141- impl Default for Application {
142- fn default ( ) -> Self {
143- Self :: Default
143+ impl Application {
144+ pub fn custom < F : Fn ( & Theme ) -> application :: Appearance + ' static > ( f : F ) -> Self {
145+ Self :: Custom ( Box :: new ( f ) )
144146 }
145147}
146148
@@ -163,7 +165,6 @@ impl application::StyleSheet for Theme {
163165/*
164166 * TODO: Button
165167 */
166- #[ derive( Clone , Copy ) ]
167168pub enum Button {
168169 Deactivated ,
169170 Destructive ,
@@ -175,8 +176,8 @@ pub enum Button {
175176 LinkActive ,
176177 Transparent ,
177178 Custom {
178- active : fn ( & Theme ) -> button:: Appearance ,
179- hover : fn ( & Theme ) -> button:: Appearance ,
179+ active : Box < dyn Fn ( & Theme ) -> button:: Appearance > ,
180+ hover : Box < dyn Fn ( & Theme ) -> button:: Appearance > ,
180181 } ,
181182}
182183
@@ -439,21 +440,16 @@ impl checkbox::StyleSheet for Theme {
439440 }
440441}
441442
442- #[ derive( Clone , Copy ) ]
443+ #[ derive( Default ) ]
443444pub enum Expander {
445+ #[ default]
444446 Default ,
445- Custom ( fn ( & Theme ) -> expander:: Appearance ) ,
446- }
447-
448- impl Default for Expander {
449- fn default ( ) -> Self {
450- Self :: Default
451- }
447+ Custom ( Box < dyn Fn ( & Theme ) -> expander:: Appearance > ) ,
452448}
453449
454- impl From < fn ( & Theme ) -> expander :: Appearance > for Expander {
455- fn from ( f : fn ( & Theme ) -> expander:: Appearance ) -> Self {
456- Self :: Custom ( f )
450+ impl Expander {
451+ pub fn custom < F : Fn ( & Theme ) -> expander:: Appearance + ' static > ( f : F ) -> Self {
452+ Self :: Custom ( Box :: new ( f ) )
457453 }
458454}
459455
@@ -471,24 +467,19 @@ impl expander::StyleSheet for Theme {
471467/*
472468 * TODO: Container
473469 */
474- #[ derive( Clone , Copy ) ]
470+ #[ derive( Default ) ]
475471pub enum Container {
476472 Background ,
477473 Primary ,
478474 Secondary ,
475+ #[ default]
479476 Transparent ,
480- Custom ( fn ( & Theme ) -> container:: Appearance ) ,
481- }
482-
483- impl Default for Container {
484- fn default ( ) -> Self {
485- Self :: Transparent
486- }
477+ Custom ( Box < dyn Fn ( & Theme ) -> container:: Appearance > ) ,
487478}
488479
489- impl From < fn ( & Theme ) -> container :: Appearance > for Container {
490- fn from ( _ : fn ( & Theme ) -> container:: Appearance ) -> Self {
491- Self :: default ( )
480+ impl Container {
481+ pub fn custom < F : Fn ( & Theme ) -> container:: Appearance + ' static > ( f : F ) -> Self {
482+ Self :: Custom ( Box :: new ( f ) )
492483 }
493484}
494485
@@ -754,17 +745,18 @@ impl pane_grid::StyleSheet for Theme {
754745/*
755746 * TODO: Progress Bar
756747 */
757- #[ derive( Clone , Copy ) ]
748+ #[ derive( Default ) ]
758749pub enum ProgressBar {
750+ #[ default]
759751 Primary ,
760752 Success ,
761753 Danger ,
762- Custom ( fn ( & Theme ) -> progress_bar:: Appearance ) ,
754+ Custom ( Box < dyn Fn ( & Theme ) -> progress_bar:: Appearance > ) ,
763755}
764756
765- impl Default for ProgressBar {
766- fn default ( ) -> Self {
767- Self :: Primary
757+ impl ProgressBar {
758+ pub fn custom < F : Fn ( & Theme ) -> progress_bar :: Appearance + ' static > ( f : F ) -> Self {
759+ Self :: Custom ( Box :: new ( f ) )
768760 }
769761}
770762
@@ -798,17 +790,18 @@ impl progress_bar::StyleSheet for Theme {
798790/*
799791 * TODO: Rule
800792 */
801- #[ derive( Clone , Copy ) ]
793+ #[ derive( Default ) ]
802794pub enum Rule {
795+ #[ default]
803796 Default ,
804797 LightDivider ,
805798 HeavyDivider ,
806- Custom ( fn ( & Theme ) -> rule:: Appearance ) ,
799+ Custom ( Box < dyn Fn ( & Theme ) -> rule:: Appearance > ) ,
807800}
808801
809- impl Default for Rule {
810- fn default ( ) -> Self {
811- Self :: Default
802+ impl Rule {
803+ pub fn custom < F : Fn ( & Theme ) -> rule :: Appearance + ' static > ( f : F ) -> Self {
804+ Self :: Custom ( Box :: new ( f ) )
812805 }
813806}
814807
@@ -883,10 +876,10 @@ impl scrollable::StyleSheet for Theme {
883876 }
884877}
885878
886- #[ derive( Default , Clone , Copy ) ]
879+ #[ derive( Clone , Default ) ]
887880pub enum Svg {
888881 /// Apply a custom appearance filter
889- Custom ( fn ( & Theme ) -> svg:: Appearance ) ,
882+ Custom ( Rc < dyn Fn ( & Theme ) -> svg:: Appearance > ) ,
890883 /// No filtering is applied
891884 #[ default]
892885 Default ,
@@ -915,6 +908,12 @@ impl Hash for Svg {
915908 }
916909}
917910
911+ impl Svg {
912+ pub fn custom < F : Fn ( & Theme ) -> svg:: Appearance + ' static > ( f : F ) -> Self {
913+ Self :: Custom ( Rc :: new ( f) )
914+ }
915+ }
916+
918917impl svg:: StyleSheet for Theme {
919918 type Style = Svg ;
920919
@@ -948,6 +947,7 @@ pub enum Text {
948947 #[ default]
949948 Default ,
950949 Color ( Color ) ,
950+ // TODO: Can't use dyn Fn since this must be copy
951951 Custom ( fn ( & Theme ) -> text:: Appearance ) ,
952952}
953953
0 commit comments