@@ -17,6 +17,7 @@ pub fn main() -> iced::Result {
1717
1818struct Image {
1919 width : f32 ,
20+ opacity : f32 ,
2021 rotation : Rotation ,
2122 content_fit : ContentFit ,
2223 spin : bool ,
@@ -26,6 +27,7 @@ struct Image {
2627#[ derive( Debug , Clone , Copy ) ]
2728enum Message {
2829 WidthChanged ( f32 ) ,
30+ OpacityChanged ( f32 ) ,
2931 RotationStrategyChanged ( RotationStrategy ) ,
3032 RotationChanged ( Degrees ) ,
3133 ContentFitChanged ( ContentFit ) ,
@@ -39,6 +41,9 @@ impl Image {
3941 Message :: WidthChanged ( width) => {
4042 self . width = width;
4143 }
44+ Message :: OpacityChanged ( opacity) => {
45+ self . opacity = opacity;
46+ }
4247 Message :: RotationStrategyChanged ( strategy) => {
4348 self . rotation = match strategy {
4449 RotationStrategy :: Floating => {
@@ -97,14 +102,15 @@ impl Image {
97102 . width( self . width)
98103 . content_fit( self . content_fit)
99104 . rotation( self . rotation)
105+ . opacity( self . opacity)
100106 )
101107 . explain( Color :: WHITE ) ,
102108 "I am Ferris!"
103109 ]
104110 . spacing ( 20 )
105111 . align_items ( Alignment :: Center ) ;
106112
107- let sizing = row ! [
113+ let fit = row ! [
108114 pick_list(
109115 [
110116 ContentFit :: Contain ,
@@ -117,19 +123,6 @@ impl Image {
117123 Message :: ContentFitChanged
118124 )
119125 . width( Length :: Fill ) ,
120- column![
121- slider( 100.0 ..=500.0 , self . width, Message :: WidthChanged ) ,
122- text( format!( "Width: {}px" , self . width) )
123- . size( 12 )
124- . line_height( 1.0 )
125- ]
126- . spacing( 2 )
127- . align_items( Alignment :: Center )
128- ]
129- . spacing ( 10 )
130- . align_items ( Alignment :: End ) ;
131-
132- let rotation = row ! [
133126 pick_list(
134127 [ RotationStrategy :: Floating , RotationStrategy :: Solid ] ,
135128 Some ( match self . rotation {
@@ -139,7 +132,21 @@ impl Image {
139132 Message :: RotationStrategyChanged ,
140133 )
141134 . width( Length :: Fill ) ,
142- column![
135+ ]
136+ . spacing ( 10 )
137+ . align_items ( Alignment :: End ) ;
138+
139+ let properties = row ! [
140+ with_value(
141+ slider( 100.0 ..=500.0 , self . width, Message :: WidthChanged ) ,
142+ format!( "Width: {}px" , self . width)
143+ ) ,
144+ with_value(
145+ slider( 0.0 ..=1.0 , self . opacity, Message :: OpacityChanged )
146+ . step( 0.01 ) ,
147+ format!( "Opacity: {:.2}" , self . opacity)
148+ ) ,
149+ with_value(
143150 row![
144151 slider(
145152 Degrees :: RANGE ,
@@ -153,20 +160,13 @@ impl Image {
153160 ]
154161 . spacing( 10 )
155162 . align_items( Alignment :: Center ) ,
156- text( format!(
157- "Rotation: {:.0}°" ,
158- f32 :: from( self . rotation. degrees( ) )
159- ) )
160- . size( 12 )
161- . line_height( 1.0 )
162- ]
163- . spacing( 2 )
164- . align_items( Alignment :: Center )
163+ format!( "Rotation: {:.0}°" , f32 :: from( self . rotation. degrees( ) ) )
164+ )
165165 ]
166166 . spacing ( 10 )
167167 . align_items ( Alignment :: End ) ;
168168
169- container ( column ! [ center( i_am_ferris) , sizing , rotation ] . spacing ( 10 ) )
169+ container ( column ! [ fit , center( i_am_ferris) , properties ] . spacing ( 10 ) )
170170 . padding ( 10 )
171171 . into ( )
172172 }
@@ -176,6 +176,7 @@ impl Default for Image {
176176 fn default ( ) -> Self {
177177 Self {
178178 width : 300.0 ,
179+ opacity : 1.0 ,
179180 rotation : Rotation :: default ( ) ,
180181 content_fit : ContentFit :: default ( ) ,
181182 spin : false ,
@@ -198,3 +199,13 @@ impl std::fmt::Display for RotationStrategy {
198199 } )
199200 }
200201}
202+
203+ fn with_value < ' a > (
204+ control : impl Into < Element < ' a , Message > > ,
205+ value : String ,
206+ ) -> Element < ' a , Message > {
207+ column ! [ control. into( ) , text( value) . size( 12 ) . line_height( 1.0 ) ]
208+ . spacing ( 2 )
209+ . align_items ( Alignment :: Center )
210+ . into ( )
211+ }
0 commit comments