Skip to content

Commit

Permalink
feat: change font size 🔍
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Dec 2, 2023
1 parent 292f3d5 commit db97e6f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
env:
binary: hello-bevy # [CHANGE]: This needs to match the project name in cargo.toml
add_binaries_to_github_release: true
# itch_target: eerii/hello-bevy # [CHANGE]: If you want to deploy to itch, set this as your username/project-url
itch_target: eerii/hello-bevy # [CHANGE]: If you want to deploy to itch, set this as your username/project-url

jobs:
get-version:
Expand Down
9 changes: 6 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use crate::{input::Bind, GameState};

pub use bevy_persistent::prelude::*;

pub const FONT_MULTIPLIERS: [f32; 3] = [2.0, 1.0, 0.8];
pub const FONT_SIZES: [f32; 5] = [16.0, 20.0, 24.0, 28.0, 32.0];

// ······
// Plugin
// ······
Expand Down Expand Up @@ -37,9 +40,9 @@ pub struct FontSize {
impl Default for FontSize {
fn default() -> Self {
Self {
title: 48.0,
text: 24.0,
button_text: 20.0,
title: FONT_SIZES[2] * FONT_MULTIPLIERS[0],
text: FONT_SIZES[2] * FONT_MULTIPLIERS[1],
button_text: FONT_SIZES[2] * FONT_MULTIPLIERS[2],
}
}
}
Expand Down
32 changes: 27 additions & 5 deletions src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(clippy::type_complexity)]

use crate::{
config::{GameOptions, Keybinds, Persistent},
config::{GameOptions, Keybinds, Persistent, FONT_MULTIPLIERS, FONT_SIZES},
input::{Bind, InputState},
ui::*,
GameState,
Expand Down Expand Up @@ -32,7 +32,7 @@ impl Plugin for MenuPlugin {
)
.add_systems(OnExit(GameState::Menu), exit_menu)
.add_systems(
Update,
PreUpdate,
clean_menu.run_if(
in_state(GameState::Menu).and_then(
state_changed::<MenuState>()
Expand Down Expand Up @@ -134,7 +134,7 @@ fn handle_buttons(
(&Interaction, &MenuButton, &Children, &mut BackgroundColor),
Changed<Interaction>,
>,
opts: Res<Persistent<GameOptions>>,
mut opts: ResMut<Persistent<GameOptions>>,
mut keybinds: ResMut<Persistent<Keybinds>>,
) {
for (inter, button, child, mut bg) in &mut buttons {
Expand Down Expand Up @@ -170,8 +170,30 @@ fn handle_buttons(
.revert_to_default()
.expect("Failed to reset keybinds");
}
MenuButton::ChangeFont(_) => {
// TODO: Change font size
MenuButton::ChangeFont(name) => {
opts.update(|opts| {
assert_eq!(FONT_MULTIPLIERS.len(), opts.font_size.field_len());
for (i, mult) in FONT_MULTIPLIERS
.iter()
.enumerate()
.take(opts.font_size.field_len())
{
if name != opts.font_size.name_at(i).unwrap() {
continue;
}
let field = opts.font_size.field_at_mut(i).unwrap();
if let Some(value) = field.downcast_mut::<f32>() {
let j = FONT_SIZES
.iter()
.position(|size| (*size - *value / mult).abs() < 1.5)
.unwrap_or(0);

*value =
(FONT_SIZES[(j + 1) % FONT_SIZES.len()] * mult).round();
}
}
})
.expect("Failed to change font size");
}
MenuButton::ChangeColor(_, _) => {
// TODO: Change color
Expand Down

0 comments on commit db97e6f

Please sign in to comment.