1- use iced:: theme:: Palette ;
1+ use iced:: application;
2+ use iced:: theme:: { self , Theme } ;
23use iced:: widget:: {
34 checkbox, column, container, horizontal_space, row, slider, text,
45} ;
@@ -22,15 +23,15 @@ struct Gradient {
2223 start : Color ,
2324 end : Color ,
2425 angle : Radians ,
25- transparent_window : bool ,
26+ transparent : bool ,
2627}
2728
2829#[ derive( Debug , Clone , Copy ) ]
2930enum Message {
3031 StartChanged ( Color ) ,
3132 EndChanged ( Color ) ,
3233 AngleChanged ( Radians ) ,
33- SetTransparent ( bool ) ,
34+ TransparentToggled ( bool ) ,
3435}
3536
3637impl Sandbox for Gradient {
@@ -41,7 +42,7 @@ impl Sandbox for Gradient {
4142 start : Color :: WHITE ,
4243 end : Color :: new ( 0.0 , 0.0 , 1.0 , 1.0 ) ,
4344 angle : Radians ( 0.0 ) ,
44- transparent_window : false ,
45+ transparent : false ,
4546 }
4647 }
4748
@@ -54,8 +55,8 @@ impl Sandbox for Gradient {
5455 Message :: StartChanged ( color) => self . start = color,
5556 Message :: EndChanged ( color) => self . end = color,
5657 Message :: AngleChanged ( angle) => self . angle = angle,
57- Message :: SetTransparent ( transparent) => {
58- self . transparent_window = transparent;
58+ Message :: TransparentToggled ( transparent) => {
59+ self . transparent = transparent;
5960 }
6061 }
6162 }
@@ -65,7 +66,7 @@ impl Sandbox for Gradient {
6566 start,
6667 end,
6768 angle,
68- transparent_window ,
69+ transparent ,
6970 } = * self ;
7071
7172 let gradient_box = container ( horizontal_space ( Length :: Fill ) )
@@ -93,8 +94,8 @@ impl Sandbox for Gradient {
9394 . align_items ( Alignment :: Center ) ;
9495
9596 let transparency_toggle = iced:: widget:: Container :: new (
96- checkbox ( "Transparent window" , transparent_window )
97- . on_toggle ( Message :: SetTransparent ) ,
97+ checkbox ( "Transparent window" , transparent )
98+ . on_toggle ( Message :: TransparentToggled ) ,
9899 )
99100 . padding ( 8 ) ;
100101
@@ -108,17 +109,16 @@ impl Sandbox for Gradient {
108109 . into ( )
109110 }
110111
111- fn theme ( & self ) -> iced:: Theme {
112- if self . transparent_window {
113- iced:: Theme :: custom (
114- String :: new ( ) ,
115- Palette {
116- background : Color :: TRANSPARENT ,
117- ..iced:: Theme :: default ( ) . palette ( )
118- } ,
119- )
112+ fn style ( & self ) -> theme:: Application {
113+ if self . transparent {
114+ theme:: Application :: custom ( |theme : & Theme | {
115+ application:: Appearance {
116+ background_color : Color :: TRANSPARENT ,
117+ text_color : theme. palette ( ) . text ,
118+ }
119+ } )
120120 } else {
121- iced :: Theme :: default ( )
121+ theme :: Application :: Default
122122 }
123123 }
124124}
0 commit comments