Skip to main content

ColChar

Struct ColChar 

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

A coloured character. Made up of text_char, a single ascii character used as the “pixel” when drawn to a Canvas, and modifier, which gives that pixel a colour or makes it bold/italic

Fields§

§text_char: char

A single ascii character used as the “pixel” when drawn to a Canvas

§modifier: Modifier

Defines the appearance of the character - colour, bold/italic, etc.

Implementations§

Source§

impl ColChar

Source

pub const SOLID: Self

A solid █ character with no Modifier.

§Example

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

An opaque whitespace character (\u{2008}) with no Modifier

ASCII Whitespaces are interpreted as transparent by ascii elements. If you want opacity, use this void 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_colour(self, colour: Colour) -> Self

Return a ColChar with the same text_char and new Modifier::Colour 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::Colour modifier from an RGB value

Examples found in repository?
examples/complex-scene.rs (line 26)
15fn main() {
16    let mut view = View::new(60, 10, BACKGROUND_CHAR);
17
18    let mut pixel = Pixel::new(Vec2D::new(5, 9), FILL_CHAR);
19
20    let mut line = Line::new(Vec2D::new(2, 8), Vec2D::new(28, 7), FILL_CHAR);
21    let mut line1_direction = -1;
22
23    let rect = Rect::new(
24        Vec2D { x: 11, y: 1 },
25        Vec2D { x: 9, y: 3 },
26        ColChar::SOLID.with_rgb(200, 30, 0),
27    );
28
29    let test_image = r"
30  ______
31 /|_||_\`.__
32(   _    _ _\
33=`-(_)--(_)-'   ";
34    let mut sprite = Sprite::new(
35        Vec2D::new(30, 1),
36        test_image,
37        Modifier::from_rgb(20, 200, 0),
38    );
39
40    let mut draw_elapsed = Duration::default();
41    let mut render_elapsed = Duration::default();
42    fps_gameloop!(
43        {
44            pixel.pos.x += 2;
45            // loop the position back to the other side. This can be done with `WrappingMode::Wrap` but it won't change the element's actual position, so the pixel position being printed would continue to increase without looping
46            pixel.pos %= view.size();
47
48            line.pos1.y += line1_direction;
49            line.pos0.y = 10 - line.pos1.y;
50            if line.pos1.y > 7 {
51                line1_direction = -1;
52            } else if line.pos1.y < 3 {
53                line1_direction = 1;
54            }
55
56            sprite.pos.x += 1;
57        },
58        {
59            view.clear();
60
61            let now = Instant::now();
62            view.wrapping_mode = WrappingMode::Panic;
63            view.draw(&pixel);
64            view.draw(&line);
65            view.draw(&rect);
66            view.wrapping_mode = WrappingMode::Wrap;
67            view.draw(&sprite);
68            draw_elapsed = now.elapsed();
69
70            let now = Instant::now();
71            let _ = view.display_render();
72            render_elapsed = now.elapsed();
73        },
74        FPS,
75        |total_elapsed: Duration, _frame_skip| {
76            println!(
77                "Drawing: {:.2?} microseconds | Rendering: {:.2?} microseconds| Total: {:.2?}",
78                draw_elapsed.as_micros(),
79                render_elapsed.as_micros(),
80                total_elapsed.as_micros()
81            );
82            println!("Pixel position: {}", pixel.pos);
83        }
84    );
85}
Source

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

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

Trait Implementations§

Source§

impl Clone for ColChar

Source§

fn clone(&self) -> ColChar

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for ColChar

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 Eq for ColChar

Source§

impl PartialEq for ColChar

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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§

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

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.