Struct GraphicBlock

Source
pub struct GraphicBlock<'a> {
    pub(crate) position: Position,
    image: Span<'a>,
    pub enabled: bool,
}
Expand description

A struct representing a graphical block that can be displayed in the game logic. It holds the position and visual representation (image) of the block.

§Fields

  • position: The position of the graphic block on the screen.
  • image: The visual representation of the block, using a styled Span.

Fields§

§position: Position§image: Span<'a>§enabled: bool

Implementations§

Source§

impl<'a> GraphicBlock<'a>

Source

pub fn new(position: Position, image: &'a str, style: Style) -> GraphicBlock<'a>

Creates a new GraphicBlock with the specified position, image, and style.

§Parameters
  • position: The position of the graphic block.
  • image: The string that represents the image of the block.
  • style: The style applied to the image of the block.
§Returns

A new GraphicBlock instance with the given position, image, and style.

§Note

If you want less lifetime propagation, this code can be refactorised to take to use a static string for the image using 'static lifetime. But for a more general use, the lifetime parameter is better, allowing dynamic text (e.g., changing each time) If you want no lifetime and dynamic text, add an own String, to GraphicBlock and generate for each rendering a new Span, but this might affect performance.

Source

pub fn set_position(&mut self, position: Position)

Sets the position of the graphic block.

§Parameters
  • position: The new position to set for the block.
Source

pub fn enable(&mut self)

Source

pub fn disable(&mut self)

Source

pub fn get_position(&self) -> &Position

Retrieves the current position of the graphic block.

§Returns

A reference to the current position of the graphic block.

Source

pub fn get_content(&self) -> &str

Retrieves the current position of the graphic block.

§Returns

A reference to the current position of the graphic block.

Trait Implementations§

Source§

impl<'a> Clone for GraphicBlock<'a>

Source§

fn clone(&self) -> GraphicBlock<'a>

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<'a> Debug for GraphicBlock<'a>

Source§

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

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

impl<'a> PartialEq for GraphicBlock<'a>

Source§

fn eq(&self, other: &GraphicBlock<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Widget for GraphicBlock<'_>

Backward compatibility implementation for the Widget trait.

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Renders the graphic block into the given buffer, using the render_ref method.

§Parameters
  • area: The area in the terminal where the graphic block should be rendered.
  • buf: A mutable reference to the buffer where the block will be drawn.
Source§

impl WidgetRef for GraphicBlock<'_>

NB: Could also have used impl Widget for &T even if more limited see: https://github.com/ratatui/ratatui/discussions/1274

Source§

fn render_ref(&self, area: Rect, buf: &mut Buffer)

Renders the graphic block into the given buffer.

§Parameters
  • area: The area in the terminal where the graphic block should be rendered.
  • buf: A mutable reference to the buffer where the block will be drawn.
§Behavior

If the block is outside the visible area, it will not be drawn, avoiding any panics. The game logic will not crash even if part of the block is outside the visible area due to window resizing.

Source§

impl<'a> StructuralPartialEq for GraphicBlock<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for GraphicBlock<'a>

§

impl<'a> RefUnwindSafe for GraphicBlock<'a>

§

impl<'a> Send for GraphicBlock<'a>

§

impl<'a> Sync for GraphicBlock<'a>

§

impl<'a> Unpin for GraphicBlock<'a>

§

impl<'a> UnwindSafe for GraphicBlock<'a>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V