Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Use Path everywhere for setting custom font
Browse files Browse the repository at this point in the history
`set_custom_font` used to take `&::std::path::Path`, but `RootInitializer::font`
was using a `&str`. This switches to `&Path` for both so we're consistent.
  • Loading branch information
tomassedovic committed May 5, 2015
1 parent bd31690 commit 82535c1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
extern crate std;

use std::marker::PhantomData;
use std::path::Path;

use bindings::ffi;
use bindings::{AsNative, FromNative, c_bool, CString, keycode_from_u32};
Expand Down Expand Up @@ -341,7 +342,7 @@ impl Root {
}
}

fn set_custom_font(font_path: &std::path::Path,
fn set_custom_font(font_path: &Path,
font_layout: FontLayout,
font_type: FontType,
nb_char_horizontal: i32,
Expand Down Expand Up @@ -387,14 +388,15 @@ struct FontDimensions(i32, i32);
/// `RootInitializer` instance:
///
/// ```rust
/// use std::path::Path;
/// use tcod::console::{Root, FontLayout, Renderer};
///
/// fn main() {
/// let mut root = Root::initializer()
/// .size(80, 20)
/// .title("Example")
/// .fullscreen(true)
/// .font("terminal.png", FontLayout::AsciiInCol)
/// .font(&Path::new("terminal.png"), FontLayout::AsciiInCol)
/// .renderer(Renderer::GLSL)
/// .init();
/// }
Expand All @@ -404,7 +406,7 @@ pub struct RootInitializer<'a> {
height: i32,
title: &'a str,
is_fullscreen: bool,
font_path: &'a str,
font_path: &'a Path,
font_layout: FontLayout,
font_type: FontType,
font_dimension: FontDimensions,
Expand All @@ -418,7 +420,7 @@ impl<'a> RootInitializer<'a> {
height: 25,
title: "Main Window",
is_fullscreen: false,
font_path: "terminal.png",
font_path: &Path::new("terminal.png"),
font_layout: FontLayout::AsciiInCol,
font_type: FontType::Default,
font_dimension: FontDimensions(0, 0),
Expand All @@ -442,7 +444,7 @@ impl<'a> RootInitializer<'a> {
self
}

pub fn font(&mut self, path: &'a str, font_layout: FontLayout) -> &mut RootInitializer<'a> {
pub fn font(&mut self, path: &'a Path, font_layout: FontLayout) -> &mut RootInitializer<'a> {
self.font_path = path;
self.font_layout = font_layout;
self
Expand All @@ -468,7 +470,7 @@ impl<'a> RootInitializer<'a> {

match self.font_dimension {
FontDimensions(horizontal, vertical) => {
Root::set_custom_font(&std::path::Path::new(self.font_path),
Root::set_custom_font(self.font_path,
self.font_layout, self.font_type,
horizontal, vertical)
}
Expand Down

0 comments on commit 82535c1

Please sign in to comment.