Skip to main content

SoftwareBackendBuilder

Struct SoftwareBackendBuilder 

Source
pub struct SoftwareBackendBuilder { /* private fields */ }
Expand description

Builder for SoftwareBackend.

§Examples

use retroglyph_software::SoftwareBackendBuilder;

// With the `default-font` feature the embedded Unscii 16 font is
// used automatically.  To supply your own 8×16 bitmap font:
//
//   use retroglyph_window::font::BitmapFont;
//   let my_font = BitmapFont::new(include_bytes!("my_font.bin"), 8, 16, 256);
//   SoftwareBackendBuilder::new().font(my_font)...

let backend = SoftwareBackendBuilder::new()
    .grid_size(80, 25)
    .build()
    .expect("backend init failed");

Implementations§

Source§

impl SoftwareBackendBuilder

Source

pub const fn new() -> Self

Creates a builder with default options.

When the default-font feature is enabled the Unscii 16 font is pre-selected; otherwise you must call font.

Source

pub const fn grid_size(self, cols: u16, rows: u16) -> Self

Sets the grid dimensions in cells.

Source

pub const fn scale(self, scale: u8) -> Self

Pixel-scale factor for the font.

Each 1-bit font pixel becomes a scale×scale block. For the VGA 8×16 font a scale of 2 gives 16×32 pixel cells, more readable on modern displays.

Source

pub fn font(self, fonts: impl Into<FontChain<'static>>) -> Self

Overrides the fonts glyphs are resolved through.

Takes either a single BitmapFont or a whole FontChain, since a lone font is a chain of one. A chain is how a grid draws characters CP437 has no mapping for (quadrants, sextants, braille): the extra coverage comes from a fallback font built with BitmapFont::with_charset, and the glyph is drawn from the bitmap font path, so it takes the cell’s foreground color like any other glyph (unlike a tileset sprite, which carries its own colors).

The cell pixel size is derived from the chain’s glyph size multiplied by scale; every font in a chain must therefore agree on its glyph size, or build fails with SoftwareBackendError::MixedGlyphSizes.

§Examples
use retroglyph_software::SoftwareBackendBuilder;
use retroglyph_window::font::{BitmapFont, FontChain, unscii16};

// A fallback font declaring the quadrant glyphs CP437 has no mapping for.
static QUADRANTS: [u8; 3 * 16] = [0; 3 * 16];
const CHARSET: [(char, u8); 3] = [('▘', 0), ('▝', 1), ('▖', 2)];
static FALLBACKS: [BitmapFont; 1] =
    [BitmapFont::with_charset(&QUADRANTS, 8, 16, 3, &CHARSET)];

let backend = SoftwareBackendBuilder::new()
    .font(FontChain::new(unscii16::FONT, &FALLBACKS))
    .build()
    .expect("backend init failed");
Source

pub fn tileset(self, opts: TilesetOptions) -> Self

Registers a tileset for loading when the backend starts.

Multiple tilesets can be registered; they are all loaded when into_renderer is called. Later registrations win on codepoint collision.

Available only when the tilesets feature is enabled.

Source

pub fn build(self) -> Result<SoftwareBackend, SoftwareBackendError>

Validates options and returns the backend configuration.

Call into_renderer on the result to obtain the renderer (hand it to retroglyph_window::winit::run_windowed to open a window).

§Errors

Returns SoftwareBackendError::NoFont if no font was set and the default-font feature is not enabled.

Returns SoftwareBackendError::MixedGlyphSizes if the configured chain’s fonts disagree on their glyph size.

Returns SoftwareBackendError::ZeroScale if scale was set to 0.

Returns SoftwareBackendError::ZeroGrid if cols or rows was set to 0.

Trait Implementations§

Source§

impl Debug for SoftwareBackendBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SoftwareBackendBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,