1
1
#![ windows_subsystem = "windows" ]
2
2
3
3
use anyhow:: Result ;
4
- use iced:: alignment:: Horizontal ;
5
4
use iced:: futures:: TryFutureExt ;
6
5
use serde:: Deserialize ;
7
6
@@ -11,7 +10,7 @@ mod install_velvet;
11
10
mod theme;
12
11
pub mod write_json;
13
12
14
- use iced:: widget:: { Column , Space , button, checkbox, column, pick_list, text} ;
13
+ use iced:: widget:: { Column , Space , button, checkbox, column, container , pick_list, text, tooltip } ;
15
14
use iced:: { Alignment , Element , Length , Size , Task , Theme , application, theme:: Palette , window} ;
16
15
17
16
#[ derive( Deserialize ) ]
@@ -51,7 +50,7 @@ enum Status {
51
50
Idle ,
52
51
Installing ,
53
52
NoVersion ,
54
- Success ( Option < Vec < String > > ) ,
53
+ Success ( Vec < String > ) ,
55
54
Failure ( String ) ,
56
55
}
57
56
@@ -124,16 +123,16 @@ impl Velvet {
124
123
} ;
125
124
}
126
125
Message :: Done ( value) => match value {
127
- Ok ( x) => match x . is_empty ( ) {
128
- true => self . status = Status :: Success ( None ) ,
129
- false => {
130
- self . status = Status :: Success ( Some ( x ) ) ;
126
+ Ok ( x) => {
127
+ let missing_mods = !x . is_empty ( ) ;
128
+ self . status = Status :: Success ( x ) ;
129
+ if missing_mods {
131
130
return window:: get_latest ( )
132
- . and_then ( move |id| window:: resize ( id, ( 500.0 , 350 .0) . into ( ) ) ) ;
133
- }
134
- } ,
135
- Err ( x ) => {
136
- self . status = Status :: Failure ( x ) ;
131
+ . and_then ( move |id| window:: resize ( id, ( 500.0 , 275 .0) . into ( ) ) ) ;
132
+ } ;
133
+ }
134
+ Err ( e ) => {
135
+ self . status = Status :: Failure ( e ) ;
137
136
return window:: get_latest ( )
138
137
. and_then ( move |id| window:: resize ( id, ( 500.0 , 275.0 ) . into ( ) ) ) ;
139
138
}
@@ -143,75 +142,74 @@ impl Velvet {
143
142
}
144
143
145
144
fn view ( & self ) -> Column < Message > {
146
- let ( button_message, extra_message) : ( & str , Element < Message > ) = match & self . status {
147
- Status :: Idle => ( "Install" , column ! ( ) . into ( ) ) ,
148
- Status :: Installing => ( "Installing..." , column ! ( ) . into ( ) ) ,
149
- Status :: NoVersion => ( "No version selected!" , column ! ( ) . into ( ) ) ,
145
+ let ( button_message, extra_message) : ( & str , Option < Element < Message > > ) = match & self . status {
146
+ Status :: Idle => ( "Install" , None ) ,
147
+ Status :: Installing => ( "Installing..." , None ) ,
148
+ Status :: NoVersion => ( "No version selected!" , None ) ,
150
149
Status :: Success ( mods) => (
151
150
"Finished!" ,
152
- match mods {
153
- Some ( mods ) => {
151
+ if ! mods. is_empty ( ) {
152
+ Some ( {
154
153
let mut mod_string = String :: new ( ) ;
155
154
mod_string. push_str ( & mods[ 0 ] ) ;
156
155
for name in mods. iter ( ) . skip ( 1 ) {
157
156
mod_string. push_str ( ", " ) ;
158
157
mod_string. push_str ( name) ;
159
158
}
160
- column ! [
161
- text( "The mods" ) ,
162
- text( mod_string)
163
- . color( theme:: LOVE )
164
- . align_x( Horizontal :: Center ) ,
165
- text( "were unavailable." )
166
- ]
167
- . align_x ( Alignment :: Center )
159
+ tooltip (
160
+ "Hover to see unavailable mods." ,
161
+ container ( text ( mod_string) ) ,
162
+ tooltip:: Position :: FollowCursor ,
163
+ )
164
+ . style ( theme:: container_style)
168
165
. into ( )
169
- }
170
- None => column ! ( ) . into ( ) ,
166
+ } )
167
+ } else {
168
+ None
171
169
} ,
172
170
) ,
173
- Status :: Failure ( message ) => ( "Error!" , text ( message ) . color ( theme:: LOVE ) . into ( ) ) ,
171
+ Status :: Failure ( e ) => ( "Error!" , Some ( text ( e ) . color ( theme:: LOVE ) . into ( ) ) ) ,
174
172
} ;
173
+
175
174
column ! [
176
- Space :: with_height( Length :: Fixed ( 10.0 ) ) ,
177
175
text( "Enter Minecraft version:" ) . size( 20 ) ,
178
- Space :: with_height( Length :: Fixed ( 5.0 ) ) ,
179
176
pick_list(
180
177
self . version_list. clone( ) ,
181
178
self . version. clone( ) ,
182
179
Message :: Update
183
180
)
184
181
. placeholder( "Loading..." )
185
182
. width( Length :: Fixed ( 200.0 ) )
186
- . style( |_ , status| theme:: pick_list_style( status ) )
187
- . menu_style( |_| theme:: menu_style( ) ) ,
188
- Space :: with_height( Length :: Fixed ( 5.0 ) ) ,
183
+ . style( theme:: pick_list_style)
184
+ . menu_style( theme:: menu_style) ,
185
+ Space :: with_height( Length :: Fill ) ,
189
186
checkbox( "Show snapshots" , self . snapshot)
190
187
. on_toggle( Message :: Snapshot )
191
- . style( |_, status| theme:: checkbox_style( status) ) ,
192
- Space :: with_height( Length :: Fill ) ,
188
+ . style( theme:: checkbox_style) ,
193
189
column![
194
190
checkbox( "Vanilla - Performance enhancing modlist." , self . vanilla, )
195
191
. on_toggle( Message :: VButton )
196
- . style( |_, status| theme:: checkbox_style( status) ) ,
197
- Space :: with_height( Length :: Fixed ( 5.0 ) ) ,
192
+ . style( theme:: checkbox_style) ,
198
193
checkbox( "Beauty - Immersive and beautiful modlist." , self . beauty, )
199
194
. on_toggle( Message :: BButton )
200
- . style( |_, status| theme:: checkbox_style( status) ) ,
201
- Space :: with_height( Length :: Fixed ( 5.0 ) ) ,
195
+ . style( theme:: checkbox_style) ,
202
196
checkbox( "Optifine - Optifine resource pack parity." , self . optifine, )
203
197
. on_toggle( Message :: OButton )
204
- . style( |_ , status| theme:: checkbox_style( status ) ) ,
198
+ . style( theme:: checkbox_style) ,
205
199
]
206
200
. align_x( Alignment :: Start ) ,
207
201
Space :: with_height( Length :: Fill ) ,
208
- extra_message,
209
- Space :: with_height( Length :: Fill ) ,
210
202
button( button_message)
211
203
. on_press( Message :: Pressed )
212
- . style( |_, status| theme:: button_style( status) ) ,
213
- Space :: with_height( Length :: Fixed ( 10.0 ) ) ,
204
+ . style( theme:: button_style) ,
205
+ if let Some ( message) = extra_message {
206
+ message
207
+ } else {
208
+ column![ ] . into( )
209
+ } ,
214
210
]
211
+ . spacing ( 5.0 )
212
+ . padding ( 10.0 )
215
213
. align_x ( Alignment :: Center )
216
214
. width ( Length :: Fill )
217
215
. height ( Length :: Fill )
0 commit comments