1
1
#![ windows_subsystem = "windows" ]
2
2
3
+ use iced:: font:: { self , Font } ;
3
4
use iced:: widget:: { Button , Column , Container , Row , Slider , Text } ;
4
5
use iced:: {
5
6
alignment:: { Horizontal , Vertical } ,
@@ -26,12 +27,21 @@ extern crate dirs;
26
27
extern crate winapi;
27
28
28
29
mod styling {
30
+ pub mod _general_styles;
29
31
pub mod button_styles;
30
32
pub mod slider_styles;
31
33
}
34
+ use styling:: _general_styles:: text_sizes;
32
35
use styling:: button_styles;
33
36
use styling:: slider_styles;
34
37
38
+ pub const MONOCRAFT : Font = Font {
39
+ family : font:: Family :: Name ( "Monocraft" ) ,
40
+ weight : font:: Weight :: Normal ,
41
+ stretch : font:: Stretch :: Normal ,
42
+ style : font:: Style :: Normal ,
43
+ } ;
44
+
35
45
#[ cfg( target_os = "windows" ) ]
36
46
use winapi:: um:: winuser:: { MessageBoxW , MB_ICONINFORMATION , MB_OK } ;
37
47
@@ -118,6 +128,7 @@ enum Message {
118
128
BackupCompleted ,
119
129
BackupError ( String ) ,
120
130
Tick ( Instant ) ,
131
+ FontLoaded ( Result < ( ) , font:: Error > ) ,
121
132
}
122
133
123
134
impl RustCraft {
@@ -176,7 +187,10 @@ impl Application for RustCraft {
176
187
image_path : "assets/normal.png" . to_string ( ) ,
177
188
..Self :: default ( )
178
189
} ,
179
- Command :: none ( ) ,
190
+ Command :: batch ( vec ! [ font:: load(
191
+ include_bytes!( "../fonts/Monocraft.ttc" ) . as_slice( ) ,
192
+ )
193
+ . map( Message :: FontLoaded ) ] ) ,
180
194
)
181
195
}
182
196
@@ -339,6 +353,8 @@ impl Application for RustCraft {
339
353
println ! ( "Selected Backup directory: {:?}" , self . backup_directory) ;
340
354
Command :: none ( )
341
355
}
356
+
357
+ _ => Command :: none ( ) ,
342
358
}
343
359
}
344
360
@@ -349,7 +365,7 @@ impl Application for RustCraft {
349
365
"Start"
350
366
} ;
351
367
352
- let mut start_button = Button :: new ( Text :: new ( start_button_text) )
368
+ let mut start_button = Button :: new ( Text :: new ( start_button_text) . font ( MONOCRAFT ) )
353
369
. padding ( 10 )
354
370
. style ( button_styles:: MinecraftButton ) ;
355
371
@@ -362,10 +378,14 @@ impl Application for RustCraft {
362
378
363
379
let control_buttons = Row :: new ( ) . spacing ( 10 ) . push ( start_button) ;
364
380
365
- let mut minecraft_dir_button = Button :: new ( Text :: new ( "Select Minecraft Directory" ) )
366
- . padding ( 10 )
367
- . width ( Length :: Fixed ( 250f32 ) )
368
- . style ( button_styles:: MinecraftButton ) ;
381
+ let mut minecraft_dir_button = Button :: new (
382
+ Text :: new ( "Select Minecraft Directory" )
383
+ . font ( MONOCRAFT )
384
+ . size ( text_sizes:: PRIMARY ) ,
385
+ )
386
+ . padding ( 10 )
387
+ . width ( Length :: Fixed ( 370f32 ) )
388
+ . style ( button_styles:: MinecraftButton ) ;
369
389
370
390
if !self . active_schedule {
371
391
minecraft_dir_button = minecraft_dir_button. on_press ( Message :: MinecraftDirPressed ) ;
@@ -377,12 +397,17 @@ impl Application for RustCraft {
377
397
. unwrap_or ( & "No directory selected" . to_string ( ) )
378
398
. clone ( ) ,
379
399
)
380
- . size ( 16 ) ;
400
+ . font ( MONOCRAFT )
401
+ . size ( text_sizes:: SECONDARY ) ;
381
402
382
- let mut backup_dir_button = Button :: new ( Text :: new ( "Select Backup Directory" ) )
383
- . padding ( 10 )
384
- . width ( Length :: Fixed ( 250f32 ) )
385
- . style ( button_styles:: MinecraftButton ) ;
403
+ let mut backup_dir_button = Button :: new (
404
+ Text :: new ( "Select Backup Directory" )
405
+ . font ( MONOCRAFT )
406
+ . size ( text_sizes:: PRIMARY ) ,
407
+ )
408
+ . padding ( 10 )
409
+ . width ( Length :: Fixed ( 370f32 ) )
410
+ . style ( button_styles:: MinecraftButton ) ;
386
411
387
412
if !self . active_schedule {
388
413
backup_dir_button = backup_dir_button. on_press ( Message :: BackupDirPressed ) ;
@@ -394,17 +419,22 @@ impl Application for RustCraft {
394
419
. unwrap_or ( & "No directory selected" . to_string ( ) )
395
420
. clone ( ) ,
396
421
)
397
- . size ( 16 ) ;
422
+ . font ( MONOCRAFT )
423
+ . size ( text_sizes:: SECONDARY ) ;
398
424
399
425
let schedule_slider = Slider :: new ( 0 ..=24 , self . schedule_hours , Message :: ScheduleChanged )
400
426
. step ( 1 )
401
427
. width ( Length :: Fixed ( 200f32 ) )
402
428
. style ( slider_styles:: MinecraftSlider ) ;
403
429
404
430
let schedule_text = if self . schedule_hours == 0 {
405
- Text :: new ( "Perform a one-time backup" ) . size ( 16 )
431
+ Text :: new ( "Perform a one-time backup" )
432
+ . font ( MONOCRAFT )
433
+ . size ( text_sizes:: SECONDARY )
406
434
} else {
407
- Text :: new ( format ! ( "Schedule every {} hours" , self . schedule_hours) ) . size ( 16 )
435
+ Text :: new ( format ! ( "Schedule every {} hours" , self . schedule_hours) )
436
+ . font ( MONOCRAFT )
437
+ . size ( text_sizes:: SECONDARY )
408
438
} ;
409
439
410
440
let minecraft_dir_column = Column :: new ( )
@@ -425,17 +455,10 @@ impl Application for RustCraft {
425
455
. padding ( 10 )
426
456
. spacing ( 10 )
427
457
. align_items ( Alignment :: Center )
428
- . push ( Text :: new ( "Select Backup Frequency" ) )
458
+ . push ( Text :: new ( "Select Backup Frequency" ) . font ( MONOCRAFT ) )
429
459
. push ( schedule_slider)
430
460
. push ( schedule_text) ;
431
461
432
- let image = Image :: new ( self . image_path . clone ( ) ) . width ( Length :: Fill ) ;
433
-
434
- let image_column = Column :: new ( )
435
- . align_items ( Alignment :: Center )
436
- . width ( Length :: FillPortion ( 1 ) )
437
- . push ( image) ;
438
-
439
462
let timer_display: Element < Message > = if self . active_schedule {
440
463
if let Some ( last_backup_time) = self . last_backup_time {
441
464
let elapsed = last_backup_time. elapsed ( ) . as_secs ( ) ;
@@ -450,6 +473,7 @@ impl Application for RustCraft {
450
473
. into ( )
451
474
} else {
452
475
Text :: new ( "Timer not initialized" )
476
+ . font ( MONOCRAFT )
453
477
. size ( 20 )
454
478
. horizontal_alignment ( Horizontal :: Center )
455
479
. vertical_alignment ( Vertical :: Center )
@@ -459,9 +483,17 @@ impl Application for RustCraft {
459
483
Text :: new ( "" ) . into ( )
460
484
} ;
461
485
486
+ let image = Image :: new ( self . image_path . clone ( ) ) . width ( Length :: Fill ) ;
487
+
488
+ let image_column = Column :: new ( )
489
+ . align_items ( Alignment :: Center )
490
+ . width ( Length :: FillPortion ( 1 ) )
491
+ . push ( image) ;
492
+
462
493
let buttons_column = Column :: new ( )
463
494
. align_items ( Alignment :: Center )
464
495
. spacing ( 20 )
496
+ . padding ( 20 )
465
497
. push ( minecraft_dir_column)
466
498
. push ( backup_dir_column)
467
499
. push ( schedule_slider_column)
0 commit comments