Struct gemini_engine::elements::view::ColChar

source ·
pub struct ColChar {
    pub text_char: char,
    pub modifier: Modifier,
}
Expand description

We use ColChar to say exactly what each pixel should look like and what colour it should be. That is, the View’s canvas is just a vector of ColChars under the hood. ColChar has the text_char and modifier properties. text_char is the single ascii character used as the “pixel” when the View is rendered, whereas modifier can give that pixel a colour or make it bold/italic

Fields§

§text_char: char

The actual character that will dictate the appearance of the pixel

§modifier: Modifier

The modifier that will be applied to the text character

Implementations§

source§

impl ColChar

source

pub const SOLID: Self = _

A solid █ character with no Modifier.

Using a sequence like this will create a red █ ColChar

ColChar::SOLID.with_rgb(255,0,0)
source

pub const BACKGROUND: Self = _

A less solid ░ character with no Modifier

source

pub const EMPTY: Self = _

A whitespace character with no Modifier

source

pub const VOID: Self = _

For use with the Sprite and Text elements, which consider a regular whitespace a transparent character

source

pub const fn new(text_char: char, modifier: Modifier) -> Self

Create a new ColChar with a text character and a Modifier

source

pub const fn with_char(self, text_char: char) -> Self

Return a ColChar with the same modifier and new text_char

source

pub const fn with_mod(self, modifier: Modifier) -> Self

Return a ColChar with the same text_char and new modifier

source

pub const fn with_rgb(self, r: u8, g: u8, b: u8) -> Self

Return a ColChar with the same text_char and new modifier of the Modifier::Colour enum variant from RGB values

Examples found in repository?
examples/complex-scene.rs (line 25)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
fn main() {
    let mut view = View::new(60, 10, BACKGROUND_CHAR);
    view.coord_numbers_in_render = true;

    let mut pixel = Pixel::new(Vec2D::from((5u8, 9u8)), FILL_CHAR);

    let mut line = Line::new(Vec2D::new(2, 8), Vec2D::new(28, 7), FILL_CHAR);
    let mut line1_direction = -1;

    let rect = Rect::new(
        Vec2D { x: 11, y: 1 },
        Vec2D { x: 9, y: 3 },
        ColChar::SOLID.with_rgb(200, 30, 0),
    );

    let test_image = r"
  ______
 /|_||_\`.__
(   _    _ _\
=`-(_)--(_)-'   ";
    let mut sprite = Sprite::new(
        Vec2D::new(30, 1),
        test_image,
        Modifier::from_rgb(20, 200, 0),
    );

    let mut blit_elapsed = Duration::default();
    let mut render_elapsed = Duration::default();
    fps_gameloop!(
        {
            pixel.pos.x += 2;
            // loop the position back to the other side. This can be done with `Wrapping::Wrap` but it won't change the element's actual position, so the pixel position being printed would continue to increase without looping
            pixel.pos %= view.size();

            line.pos1.y += line1_direction;
            line.pos0.y = 10 - line.pos1.y;
            if line.pos1.y > 7 {
                line1_direction = -1;
            } else if line.pos1.y < 3 {
                line1_direction = 1;
            }

            sprite.pos.x += 1;
        },
        {
            view.clear();

            let now = Instant::now();
            view.blit(&pixel, Wrapping::Panic);
            view.blit(&line, Wrapping::Panic);
            view.blit(&rect, Wrapping::Panic);
            view.blit(&sprite, Wrapping::Wrap);
            blit_elapsed = now.elapsed();

            let now = Instant::now();
            let _ = view.display_render();
            render_elapsed = now.elapsed();
        },
        FPS,
        |total_elapsed: Duration, _frame_skip| {
            println!(
                "Blitting: {:.2?} microseconds | Rendering: {:.2?} microseconds| Total: {:.2?}",
                blit_elapsed.as_micros(),
                render_elapsed.as_micros(),
                total_elapsed.as_micros()
            );
            println!("Pixel position: {}", pixel.pos);
        }
    );
}
source

pub fn with_hsv(self, h: u8, s: u8, v: u8) -> Self

Return a ColChar with the same text_char and new modifier of the Modifier::Colour enum variant from HSV values

source

pub const fn with_colour(self, colour: Colour) -> Self

Return a ColChar with the same text_char and new modifier of the Modifier::Colour enum variant from an HSV value

Trait Implementations§

source§

impl Clone for ColChar

source§

fn clone(&self) -> ColChar

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ColChar

source§

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

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

impl Default for ColChar

source§

fn default() -> Self

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

impl Display for ColChar

source§

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

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

impl PartialEq for ColChar

source§

fn eq(&self, other: &ColChar) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for ColChar

source§

impl Eq for ColChar

source§

impl StructuralPartialEq for ColChar

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
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.