1
- use iced:: { Application , Command , Element , executor, Length , Settings , Theme } ;
2
1
use iced:: alignment;
3
2
use iced:: widget:: { column, container, text} ;
3
+ use iced:: { executor, Application , Command , Element , Length , Settings , Theme } ;
4
4
use iced_aw:: native:: cupertino:: cupertino_spinner:: CupertinoSpinner ;
5
5
6
6
pub fn main ( ) -> iced:: Result {
7
- Spinner :: run ( Settings { antialiasing : true , ..Settings :: default ( ) } )
7
+ Spinner :: run ( Settings {
8
+ antialiasing : true ,
9
+ ..Settings :: default ( )
10
+ } )
8
11
}
9
12
10
13
#[ derive( Debug , Clone ) ]
@@ -26,66 +29,67 @@ impl State {
26
29
async fn load ( ) -> Result < State , ( ) > {
27
30
println ! ( "Doing stuff..." ) ;
28
31
tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 3 ) ) . await ;
29
- return Ok ( Self { hello : "Loaded!" . to_string ( ) } ) ;
32
+ return Ok ( Self {
33
+ hello : "Loaded!" . to_string ( ) ,
34
+ } ) ;
30
35
}
31
36
}
32
37
33
38
impl Application for Spinner {
34
39
type Executor = executor:: Default ;
35
- type Message = Message ;
36
- type Theme = Theme ;
37
- type Flags = ( ) ;
40
+ type Message = Message ;
41
+ type Theme = Theme ;
42
+ type Flags = ( ) ;
38
43
39
44
fn new ( _flags : ( ) ) -> ( Self , Command < Message > ) {
40
- ( Spinner :: Loading , Command :: perform ( State :: load ( ) , Message :: Loaded ) )
45
+ (
46
+ Spinner :: Loading ,
47
+ Command :: perform ( State :: load ( ) , Message :: Loaded ) ,
48
+ )
41
49
}
42
50
43
- fn title ( & self ) -> String { String :: from ( "CupertinoSpinner - Iced" ) }
51
+ fn title ( & self ) -> String {
52
+ String :: from ( "CupertinoSpinner - Iced" )
53
+ }
44
54
45
55
fn update ( & mut self , message : Message ) -> Command < Message > {
46
56
match self {
47
- Spinner :: Loading => {
48
- match message {
49
- Message :: Loaded ( Ok ( state) ) => {
50
- * self = Spinner :: Loaded ( State {
51
- hello : state. hello ,
52
- } ) ;
53
- } ,
54
-
55
- _ => ( )
57
+ Spinner :: Loading => match message {
58
+ Message :: Loaded ( Ok ( state) ) => {
59
+ * self = Spinner :: Loaded ( State { hello : state. hello } ) ;
56
60
}
57
- } ,
58
61
59
- _ => ( )
62
+ _ => ( ) ,
63
+ } ,
60
64
65
+ _ => ( ) ,
61
66
}
62
67
63
68
Command :: none ( )
64
69
}
65
70
66
71
fn view ( & self ) -> Element < Message > {
67
72
match self {
68
- Spinner :: Loading => {
69
- container (
70
- CupertinoSpinner :: new ( ) . width ( Length :: Fill ) . height ( Length :: Fill )
71
- ) . into ( )
72
- } ,
73
-
74
- Spinner :: Loaded ( state) => {
75
- container ( column ! [ text( & state. hello)
76
- . width( Length :: Fill )
77
- . size( 25 )
78
- . horizontal_alignment( alignment:: Horizontal :: Center )
79
- . vertical_alignment( alignment:: Vertical :: Center )
80
- ] )
73
+ Spinner :: Loading => container (
74
+ CupertinoSpinner :: new ( )
81
75
. width ( Length :: Fill )
82
- . height ( Length :: Fill )
83
- . center_y ( )
84
- . into ( )
85
- } ,
76
+ . height ( Length :: Fill ) ,
77
+ )
78
+ . into ( ) ,
79
+
80
+ Spinner :: Loaded ( state) => container ( column ! [ text( & state. hello)
81
+ . width( Length :: Fill )
82
+ . size( 25 )
83
+ . horizontal_alignment( alignment:: Horizontal :: Center )
84
+ . vertical_alignment( alignment:: Vertical :: Center ) ] )
85
+ . width ( Length :: Fill )
86
+ . height ( Length :: Fill )
87
+ . center_y ( )
88
+ . into ( ) ,
86
89
}
87
90
}
88
91
89
- fn theme ( & self ) -> Self :: Theme { Theme :: Light }
92
+ fn theme ( & self ) -> Self :: Theme {
93
+ Theme :: Light
94
+ }
90
95
}
91
-
0 commit comments