From 0e2bc757bcbb68c7930dd33b0a2329c0151e1153 Mon Sep 17 00:00:00 2001 From: Yash Karandikar Date: Wed, 16 Mar 2022 11:54:51 -0500 Subject: [PATCH] Rustfmt --- src/lib.rs | 41 +++++++++++++++++++++++++---------------- src/main.rs | 15 +++++++++++++-- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c0b6c97..98c9443 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,8 +56,9 @@ use sdl2::{ render::{Canvas, TextureCreator, TextureValueError}, rwops::RWops, surface::Surface, + ttf::{FontError, Sdl2TtfContext}, video::{Window, WindowBuildError, WindowContext}, - EventPump, IntegerOrSdlError, ttf::{Sdl2TtfContext, FontError}, + EventPump, IntegerOrSdlError, }; #[doc(no_inline)] @@ -245,7 +246,7 @@ impl Sprite { pub struct Context { canvas: Canvas, texture_creator: TextureCreator, - ttf_subsystem: Sdl2TtfContext + ttf_subsystem: Sdl2TtfContext, } impl Context { @@ -254,7 +255,7 @@ impl Context { Self { canvas, texture_creator: creator, - ttf_subsystem + ttf_subsystem, } } @@ -282,26 +283,24 @@ impl Context { /// Set the mode for drawing text. pub enum TextMode { /// Render the text transparently. - Transparent { - colour: (u8, u8, u8) - }, + Transparent { colour: (u8, u8, u8) }, /// Render the text with a foreground and a background colour. - /// + /// /// This creates a box around the text. Shaded { foreground: (u8, u8, u8), - background: (u8, u8, u8) - } + background: (u8, u8, u8), + }, } /// Draw text to the screen. -/// +/// /// This loads a font from the current directory, case sensitive. -/// +/// /// `pos` refers to the *center* of the rendered text. -/// +/// /// Refer to [`TextMode`] for information about colouring. -/// +/// /// ``` no_run /// # use cat_box::*; /// # let game = Game::new("", 100, 100); @@ -312,13 +311,23 @@ pub enum TextMode { /// }; /// draw_text(ctx, "text to draw", "arial.ttf", 72, (300, 300), mode); /// # }); -pub fn draw_text>(ctx: &mut Context, text: S, font: &str, size: u16, pos: (i32, i32), mode: TextMode) -> Result<()> { - let font = ctx.ttf_subsystem.load_font(font, size)?; +pub fn draw_text>( + ctx: &mut Context, + text: S, + font: &str, + size: u16, + pos: (i32, i32), + mode: TextMode, +) -> Result<()> { + let font = ctx.ttf_subsystem.load_font(font, size)?; let renderer = font.render(text.as_ref()); let surf = match mode { TextMode::Transparent { colour: (r, g, b) } => renderer.solid(Color::RGB(r, g, b)), - TextMode::Shaded { foreground: (fr, fg, fb), background: (br, bg, bb) } => renderer.shaded(Color::RGB(fr, fg, fb), Color::RGB(br, bg, bb)), + TextMode::Shaded { + foreground: (fr, fg, fb), + background: (br, bg, bb), + } => renderer.shaded(Color::RGB(fr, fg, fb), Color::RGB(br, bg, bb)), }?; drop(font); diff --git a/src/main.rs b/src/main.rs index d8fa369..568aa3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use cat_box::{Event, Game, Keycode, Sprite, draw_text}; +use cat_box::{draw_text, Event, Game, Keycode, Sprite}; fn main() { let game = Game::new("catbox demo", 1000, 800); @@ -10,7 +10,18 @@ fn main() { i = (i + 1.0) % 360.0; ctx.set_background_colour(i as u8, 64, 255); - draw_text(ctx, format!("i is {}", i), "MesloLGS NF Regular.ttf", 72, (300, 300), cat_box::TextMode::Shaded {foreground: (255, 255, 255), background: (0, 0, 0)}).unwrap(); + draw_text( + ctx, + format!("i is {}", i), + "MesloLGS NF Regular.ttf", + 72, + (300, 300), + cat_box::TextMode::Shaded { + foreground: (255, 255, 255), + background: (0, 0, 0), + }, + ) + .unwrap(); let (start_x, start_y) = s.position(); let m = sdl2::mouse::MouseState::new(event_pump.as_ref());