Skip to content

Commit 9e34290

Browse files
Merge pull request #5 from FrancescoCoding/rustcraft-4
Change font to Monocraft
2 parents a5d3263 + 9dac789 commit 9e34290

File tree

4 files changed

+62
-22
lines changed

4 files changed

+62
-22
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
.idea
2+
.idea/*
3+
14
/target
25
config.json

fonts/Monocraft.ttc

3.1 MB
Binary file not shown.

src/main.rs

+54-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![windows_subsystem = "windows"]
22

3+
use iced::font::{self, Font};
34
use iced::widget::{Button, Column, Container, Row, Slider, Text};
45
use iced::{
56
alignment::{Horizontal, Vertical},
@@ -26,12 +27,21 @@ extern crate dirs;
2627
extern crate winapi;
2728

2829
mod styling {
30+
pub mod _general_styles;
2931
pub mod button_styles;
3032
pub mod slider_styles;
3133
}
34+
use styling::_general_styles::text_sizes;
3235
use styling::button_styles;
3336
use styling::slider_styles;
3437

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+
3545
#[cfg(target_os = "windows")]
3646
use winapi::um::winuser::{MessageBoxW, MB_ICONINFORMATION, MB_OK};
3747

@@ -118,6 +128,7 @@ enum Message {
118128
BackupCompleted,
119129
BackupError(String),
120130
Tick(Instant),
131+
FontLoaded(Result<(), font::Error>),
121132
}
122133

123134
impl RustCraft {
@@ -176,7 +187,10 @@ impl Application for RustCraft {
176187
image_path: "assets/normal.png".to_string(),
177188
..Self::default()
178189
},
179-
Command::none(),
190+
Command::batch(vec![font::load(
191+
include_bytes!("../fonts/Monocraft.ttc").as_slice(),
192+
)
193+
.map(Message::FontLoaded)]),
180194
)
181195
}
182196

@@ -339,6 +353,8 @@ impl Application for RustCraft {
339353
println!("Selected Backup directory: {:?}", self.backup_directory);
340354
Command::none()
341355
}
356+
357+
_ => Command::none(),
342358
}
343359
}
344360

@@ -349,7 +365,7 @@ impl Application for RustCraft {
349365
"Start"
350366
};
351367

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))
353369
.padding(10)
354370
.style(button_styles::MinecraftButton);
355371

@@ -362,10 +378,14 @@ impl Application for RustCraft {
362378

363379
let control_buttons = Row::new().spacing(10).push(start_button);
364380

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);
369389

370390
if !self.active_schedule {
371391
minecraft_dir_button = minecraft_dir_button.on_press(Message::MinecraftDirPressed);
@@ -377,12 +397,17 @@ impl Application for RustCraft {
377397
.unwrap_or(&"No directory selected".to_string())
378398
.clone(),
379399
)
380-
.size(16);
400+
.font(MONOCRAFT)
401+
.size(text_sizes::SECONDARY);
381402

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);
386411

387412
if !self.active_schedule {
388413
backup_dir_button = backup_dir_button.on_press(Message::BackupDirPressed);
@@ -394,17 +419,22 @@ impl Application for RustCraft {
394419
.unwrap_or(&"No directory selected".to_string())
395420
.clone(),
396421
)
397-
.size(16);
422+
.font(MONOCRAFT)
423+
.size(text_sizes::SECONDARY);
398424

399425
let schedule_slider = Slider::new(0..=24, self.schedule_hours, Message::ScheduleChanged)
400426
.step(1)
401427
.width(Length::Fixed(200f32))
402428
.style(slider_styles::MinecraftSlider);
403429

404430
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)
406434
} 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)
408438
};
409439

410440
let minecraft_dir_column = Column::new()
@@ -425,17 +455,10 @@ impl Application for RustCraft {
425455
.padding(10)
426456
.spacing(10)
427457
.align_items(Alignment::Center)
428-
.push(Text::new("Select Backup Frequency"))
458+
.push(Text::new("Select Backup Frequency").font(MONOCRAFT))
429459
.push(schedule_slider)
430460
.push(schedule_text);
431461

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-
439462
let timer_display: Element<Message> = if self.active_schedule {
440463
if let Some(last_backup_time) = self.last_backup_time {
441464
let elapsed = last_backup_time.elapsed().as_secs();
@@ -450,6 +473,7 @@ impl Application for RustCraft {
450473
.into()
451474
} else {
452475
Text::new("Timer not initialized")
476+
.font(MONOCRAFT)
453477
.size(20)
454478
.horizontal_alignment(Horizontal::Center)
455479
.vertical_alignment(Vertical::Center)
@@ -459,9 +483,17 @@ impl Application for RustCraft {
459483
Text::new("").into()
460484
};
461485

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+
462493
let buttons_column = Column::new()
463494
.align_items(Alignment::Center)
464495
.spacing(20)
496+
.padding(20)
465497
.push(minecraft_dir_column)
466498
.push(backup_dir_column)
467499
.push(schedule_slider_column)

src/styling/_general_styles.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub mod text_sizes {
2+
pub const PRIMARY: u16 = 18;
3+
pub const SECONDARY: u16 = 16;
4+
// pub const SMALL: u16 = 14;
5+
}

0 commit comments

Comments
 (0)