From 19a75825fc423a47751305ea21e2b6df483348df Mon Sep 17 00:00:00 2001 From: Raptorox <70806316+Raptorox@users.noreply.github.com> Date: Fri, 10 Oct 2025 14:45:50 +0200 Subject: [PATCH] lint --- src/button.rs | 33 +++++++++++++++++++-------------- src/counter.rs | 30 ++++++++++++++++++++---------- src/main.rs | 28 +++++++++++++++++++--------- 3 files changed, 58 insertions(+), 33 deletions(-) diff --git a/src/button.rs b/src/button.rs index 26c20a2..135e5da 100644 --- a/src/button.rs +++ b/src/button.rs @@ -1,14 +1,23 @@ -use sfml::{graphics::{CircleShape, Drawable, Font, Shape, Text, Transformable}, system::Vector2f}; +use sfml::{ + graphics::{CircleShape, Drawable, Font, Shape, Text, Transformable}, + system::Vector2f, +}; use crate::constants::button::{DEFAULT_BG_COLOR, DEFAULT_TXT_COLOR, PRECISION}; pub struct Button<'a> { background: CircleShape<'a>, - text: Text<'a> + text: Text<'a>, } impl<'a> Button<'a> { - pub fn new(text: String, font: &'a Font, font_size: u32, pos: impl Into, radius: f32) -> Self { + pub fn new( + text: String, + font: &'a Font, + font_size: u32, + pos: impl Into, + radius: f32, + ) -> Self { let mut background = CircleShape::new(radius, PRECISION); background.set_origin((radius, radius)); background.set_position(pos); @@ -17,17 +26,14 @@ impl<'a> Button<'a> { let mut text = Text::new(&text, font, font_size); text.set_position(background.position()); text.set_fill_color(DEFAULT_TXT_COLOR); - + let bounds = text.local_bounds(); text.set_origin(( bounds.left + bounds.width / 2., bounds.top + bounds.height / 2., )); - Button { - background, - text - } + Button { background, text } } pub fn contains(&self, m_pos: Vector2f) -> bool { @@ -37,12 +43,11 @@ impl<'a> Button<'a> { impl<'d> Drawable for Button<'d> { fn draw<'a: 'shader, 'texture, 'shader, 'shader_texture>( - &'a self, - target: &mut dyn sfml::graphics::RenderTarget, - states: &sfml::graphics::RenderStates<'texture, 'shader, 'shader_texture>, - ) { - + &'a self, + target: &mut dyn sfml::graphics::RenderTarget, + states: &sfml::graphics::RenderStates<'texture, 'shader, 'shader_texture>, + ) { self.background.draw(target, states); self.text.draw(target, states); } -} \ No newline at end of file +} diff --git a/src/counter.rs b/src/counter.rs index 69ab2b7..f074c06 100644 --- a/src/counter.rs +++ b/src/counter.rs @@ -3,7 +3,17 @@ use sfml::{ system::Vector2f, }; -use crate::{button::Button, constants::{button::{FONT_SIZE_BIG, FONT_SIZE_SMALL, RADIUS_BIG, RADIUS_SMALL}, common::WINDOW_SIZE_F, counter::{DEFAULT_BG_COLOR, DEFAULT_OUTLINE_COLOR, DEFAULT_OUTLINE_THICKNESS, FONT_SIZE, HOFFSET_PERC, SIZE, VOFFSET_PERC}}}; +use crate::{ + button::Button, + constants::{ + button::{FONT_SIZE_BIG, FONT_SIZE_SMALL, RADIUS_BIG, RADIUS_SMALL}, + common::WINDOW_SIZE_F, + counter::{ + DEFAULT_BG_COLOR, DEFAULT_OUTLINE_COLOR, DEFAULT_OUTLINE_THICKNESS, FONT_SIZE, + HOFFSET_PERC, SIZE, VOFFSET_PERC, + }, + }, +}; pub struct Counter<'a> { count: u32, @@ -20,7 +30,7 @@ impl<'a> Counter<'a> { background.set_fill_color(DEFAULT_BG_COLOR); background.set_outline_color(DEFAULT_OUTLINE_COLOR); background.set_outline_thickness(DEFAULT_OUTLINE_THICKNESS); - background.set_position((WINDOW_SIZE_F.0/2., WINDOW_SIZE_F.1/2.)); + background.set_position((WINDOW_SIZE_F.0 / 2., WINDOW_SIZE_F.1 / 2.)); let bounds = background.local_bounds(); background.set_origin(( bounds.left + bounds.width / 2., @@ -29,7 +39,7 @@ impl<'a> Counter<'a> { let mut count_str = Text::new(&count.to_string(), font, FONT_SIZE); count_str.set_fill_color(Color::BLACK); - count_str.set_position((WINDOW_SIZE_F.0/2., WINDOW_SIZE_F.1/2.)); + count_str.set_position((WINDOW_SIZE_F.0 / 2., WINDOW_SIZE_F.1 / 2.)); let bounds = count_str.local_bounds(); count_str.set_origin(( bounds.left + bounds.width / 2., @@ -41,10 +51,10 @@ impl<'a> Counter<'a> { font, FONT_SIZE_BIG, Vector2f::new( - background.position().x - HOFFSET_PERC*background.size().x, + background.position().x - HOFFSET_PERC * background.size().x, background.position().y, ), - RADIUS_BIG + RADIUS_BIG, ); let inc_button = Button::new( @@ -52,10 +62,10 @@ impl<'a> Counter<'a> { font, FONT_SIZE_BIG, Vector2f::new( - background.position().x + HOFFSET_PERC*background.size().x, + background.position().x + HOFFSET_PERC * background.size().x, background.position().y, ), - RADIUS_BIG + RADIUS_BIG, ); let reset_button = Button::new( @@ -64,9 +74,9 @@ impl<'a> Counter<'a> { FONT_SIZE_SMALL, Vector2f::new( background.position().x, - background.position().y + (1. - VOFFSET_PERC)*background.size().y/2. + background.position().y + (1. - VOFFSET_PERC) * background.size().y / 2., ), - RADIUS_SMALL + RADIUS_SMALL, ); Counter { @@ -123,7 +133,7 @@ impl<'a> Counter<'a> { } } } - + impl<'d> Drawable for Counter<'d> { fn draw<'a: 'shader, 'texture, 'shader, 'shader_texture>( &'a self, diff --git a/src/main.rs b/src/main.rs index a2d0fd7..7d0fa99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,26 @@ -use sfml::{graphics::{Color, Font, RenderTarget, RenderWindow}, window::{mouse, Event, Key, Style}, SfResult}; +use sfml::{ + SfResult, + graphics::{Color, Font, RenderTarget, RenderWindow}, + window::{Event, Key, Style, mouse}, +}; -mod counter; mod button; mod constants; +mod counter; -use counter::Counter; use crate::constants::common::{FPS, WINDOW_SIZE}; +use counter::Counter; - -fn main() -> SfResult<()>{ +fn main() -> SfResult<()> { let font = Font::from_file("res/font.ttf").unwrap(); let mut c1 = Counter::new(0, &font); - let mut window = RenderWindow::new(WINDOW_SIZE, "Multi Counter", Style::CLOSE, &Default::default())?; + let mut window = RenderWindow::new( + WINDOW_SIZE, + "Multi Counter", + Style::CLOSE, + &Default::default(), + )?; window.set_framerate_limit(FPS); while window.is_open() { @@ -25,8 +33,10 @@ fn main() -> SfResult<()>{ Key::Space => c1.reset(), _ => {} }, - Event::MouseButtonPressed { button, x, y } => if button == mouse::Button::Left { - c1.handle_mouse((x as f32, y as f32)); + Event::MouseButtonPressed { button, x, y } => { + if button == mouse::Button::Left { + c1.handle_mouse((x as f32, y as f32)); + } } _ => {} } @@ -36,6 +46,6 @@ fn main() -> SfResult<()>{ window.draw(&c1); window.display(); } - + Ok(()) }