Skip to content

Commit

Permalink
Merge pull request #5 from FrancescoCoding/rustcraft-4
Browse files Browse the repository at this point in the history
Change font to Monocraft
  • Loading branch information
sundaram123krishnan authored Aug 25, 2024
2 parents a5d3263 + 9dac789 commit 9e34290
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.idea
.idea/*

/target
config.json
Binary file added fonts/Monocraft.ttc
Binary file not shown.
76 changes: 54 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![windows_subsystem = "windows"]

use iced::font::{self, Font};
use iced::widget::{Button, Column, Container, Row, Slider, Text};
use iced::{
alignment::{Horizontal, Vertical},
Expand All @@ -26,12 +27,21 @@ extern crate dirs;
extern crate winapi;

mod styling {
pub mod _general_styles;
pub mod button_styles;
pub mod slider_styles;
}
use styling::_general_styles::text_sizes;
use styling::button_styles;
use styling::slider_styles;

pub const MONOCRAFT: Font = Font {
family: font::Family::Name("Monocraft"),
weight: font::Weight::Normal,
stretch: font::Stretch::Normal,
style: font::Style::Normal,
};

#[cfg(target_os = "windows")]
use winapi::um::winuser::{MessageBoxW, MB_ICONINFORMATION, MB_OK};

Expand Down Expand Up @@ -118,6 +128,7 @@ enum Message {
BackupCompleted,
BackupError(String),
Tick(Instant),
FontLoaded(Result<(), font::Error>),
}

impl RustCraft {
Expand Down Expand Up @@ -176,7 +187,10 @@ impl Application for RustCraft {
image_path: "assets/normal.png".to_string(),
..Self::default()
},
Command::none(),
Command::batch(vec![font::load(
include_bytes!("../fonts/Monocraft.ttc").as_slice(),
)
.map(Message::FontLoaded)]),
)
}

Expand Down Expand Up @@ -339,6 +353,8 @@ impl Application for RustCraft {
println!("Selected Backup directory: {:?}", self.backup_directory);
Command::none()
}

_ => Command::none(),
}
}

Expand All @@ -349,7 +365,7 @@ impl Application for RustCraft {
"Start"
};

let mut start_button = Button::new(Text::new(start_button_text))
let mut start_button = Button::new(Text::new(start_button_text).font(MONOCRAFT))
.padding(10)
.style(button_styles::MinecraftButton);

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

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

let mut minecraft_dir_button = Button::new(Text::new("Select Minecraft Directory"))
.padding(10)
.width(Length::Fixed(250f32))
.style(button_styles::MinecraftButton);
let mut minecraft_dir_button = Button::new(
Text::new("Select Minecraft Directory")
.font(MONOCRAFT)
.size(text_sizes::PRIMARY),
)
.padding(10)
.width(Length::Fixed(370f32))
.style(button_styles::MinecraftButton);

if !self.active_schedule {
minecraft_dir_button = minecraft_dir_button.on_press(Message::MinecraftDirPressed);
Expand All @@ -377,12 +397,17 @@ impl Application for RustCraft {
.unwrap_or(&"No directory selected".to_string())
.clone(),
)
.size(16);
.font(MONOCRAFT)
.size(text_sizes::SECONDARY);

let mut backup_dir_button = Button::new(Text::new("Select Backup Directory"))
.padding(10)
.width(Length::Fixed(250f32))
.style(button_styles::MinecraftButton);
let mut backup_dir_button = Button::new(
Text::new("Select Backup Directory")
.font(MONOCRAFT)
.size(text_sizes::PRIMARY),
)
.padding(10)
.width(Length::Fixed(370f32))
.style(button_styles::MinecraftButton);

if !self.active_schedule {
backup_dir_button = backup_dir_button.on_press(Message::BackupDirPressed);
Expand All @@ -394,17 +419,22 @@ impl Application for RustCraft {
.unwrap_or(&"No directory selected".to_string())
.clone(),
)
.size(16);
.font(MONOCRAFT)
.size(text_sizes::SECONDARY);

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

let schedule_text = if self.schedule_hours == 0 {
Text::new("Perform a one-time backup").size(16)
Text::new("Perform a one-time backup")
.font(MONOCRAFT)
.size(text_sizes::SECONDARY)
} else {
Text::new(format!("Schedule every {} hours", self.schedule_hours)).size(16)
Text::new(format!("Schedule every {} hours", self.schedule_hours))
.font(MONOCRAFT)
.size(text_sizes::SECONDARY)
};

let minecraft_dir_column = Column::new()
Expand All @@ -425,17 +455,10 @@ impl Application for RustCraft {
.padding(10)
.spacing(10)
.align_items(Alignment::Center)
.push(Text::new("Select Backup Frequency"))
.push(Text::new("Select Backup Frequency").font(MONOCRAFT))
.push(schedule_slider)
.push(schedule_text);

let image = Image::new(self.image_path.clone()).width(Length::Fill);

let image_column = Column::new()
.align_items(Alignment::Center)
.width(Length::FillPortion(1))
.push(image);

let timer_display: Element<Message> = if self.active_schedule {
if let Some(last_backup_time) = self.last_backup_time {
let elapsed = last_backup_time.elapsed().as_secs();
Expand All @@ -450,6 +473,7 @@ impl Application for RustCraft {
.into()
} else {
Text::new("Timer not initialized")
.font(MONOCRAFT)
.size(20)
.horizontal_alignment(Horizontal::Center)
.vertical_alignment(Vertical::Center)
Expand All @@ -459,9 +483,17 @@ impl Application for RustCraft {
Text::new("").into()
};

let image = Image::new(self.image_path.clone()).width(Length::Fill);

let image_column = Column::new()
.align_items(Alignment::Center)
.width(Length::FillPortion(1))
.push(image);

let buttons_column = Column::new()
.align_items(Alignment::Center)
.spacing(20)
.padding(20)
.push(minecraft_dir_column)
.push(backup_dir_column)
.push(schedule_slider_column)
Expand Down
5 changes: 5 additions & 0 deletions src/styling/_general_styles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod text_sizes {
pub const PRIMARY: u16 = 18;
pub const SECONDARY: u16 = 16;
// pub const SMALL: u16 = 14;
}

0 comments on commit 9e34290

Please sign in to comment.