move repeated 'PixelType' type constraints to new Pixel trait
This commit is contained in:
parent
986a2a9677
commit
75401cb5c7
|
@ -8,13 +8,11 @@
|
|||
|
||||
use std::error::Error;
|
||||
|
||||
use num_traits::{PrimInt, Unsigned};
|
||||
|
||||
use crate::graphics::indexed;
|
||||
use crate::graphics::{indexed, Pixel};
|
||||
use crate::math::Rect;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum GeneralBlitMethod<PixelType: PrimInt + Unsigned> {
|
||||
pub enum GeneralBlitMethod<PixelType: Pixel> {
|
||||
Solid,
|
||||
Transparent(PixelType),
|
||||
}
|
||||
|
@ -23,7 +21,7 @@ pub enum GeneralBlitMethod<PixelType: PrimInt + Unsigned> {
|
|||
/// drawing functionality that is to be made generic across all supported bitmap types and is not specific to
|
||||
/// any one pixel-depth. Note that this does not provide cross-bit-depth drawing support.
|
||||
pub trait GeneralBitmap: Sized + Clone {
|
||||
type PixelType: PrimInt + Unsigned;
|
||||
type PixelType: Pixel;
|
||||
type ErrorType: Error;
|
||||
|
||||
/// Creates a new bitmap with the specified dimensions, in pixels.
|
||||
|
|
|
@ -4,11 +4,9 @@ use std::io::{BufReader, BufWriter, Cursor};
|
|||
use std::path::Path;
|
||||
|
||||
use byteorder::{ReadBytesExt, WriteBytesExt};
|
||||
use num_traits::{PrimInt, Unsigned};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::graphics::*;
|
||||
use crate::graphics::indexed::*;
|
||||
use crate::math::*;
|
||||
|
||||
pub static VGA_FONT_BYTES: &[u8] = include_bytes!("../../assets/vga.fnt");
|
||||
|
@ -27,7 +25,7 @@ pub enum FontError {
|
|||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
pub enum FontRenderOpts<PixelType: PrimInt + Unsigned> {
|
||||
pub enum FontRenderOpts<PixelType: Pixel> {
|
||||
Color(PixelType),
|
||||
None,
|
||||
}
|
||||
|
@ -47,7 +45,7 @@ pub trait Font {
|
|||
fn line_height(&self) -> u8;
|
||||
fn measure<PixelType>(&self, text: &str, opts: FontRenderOpts<PixelType>) -> (u32, u32)
|
||||
where
|
||||
PixelType: PrimInt + Unsigned;
|
||||
PixelType: Pixel;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
|
@ -210,7 +208,7 @@ impl Font for BitmaskFont {
|
|||
|
||||
fn measure<PixelType>(&self, text: &str, _opts: FontRenderOpts<PixelType>) -> (u32, u32)
|
||||
where
|
||||
PixelType: PrimInt + Unsigned
|
||||
PixelType: Pixel
|
||||
{
|
||||
if text.is_empty() {
|
||||
return (0, 0);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use num_traits::{PrimInt, Unsigned};
|
||||
|
||||
pub use self::bitmap::*;
|
||||
pub use self::bitmapatlas::*;
|
||||
pub use self::font::*;
|
||||
|
@ -7,3 +9,7 @@ pub mod bitmapatlas;
|
|||
pub mod font;
|
||||
pub mod indexed;
|
||||
pub mod rgb;
|
||||
|
||||
/// Common trait to represent single pixel/colour values.
|
||||
pub trait Pixel: PrimInt + Unsigned {}
|
||||
impl<T> Pixel for T where T: PrimInt + Unsigned {}
|
||||
|
|
Loading…
Reference in a new issue