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 styledSpan
.
Fields§
§position: Position
§image: Span<'a>
§enabled: bool
Implementations§
Source§impl<'a> GraphicBlock<'a>
impl<'a> GraphicBlock<'a>
Sourcepub fn new(position: Position, image: &'a str, style: Style) -> GraphicBlock<'a>
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.
Sourcepub fn set_position(&mut self, position: Position)
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.
pub fn enable(&mut self)
pub fn disable(&mut self)
Sourcepub fn get_position(&self) -> &Position
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.
Sourcepub fn get_content(&self) -> &str
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>
impl<'a> Clone for GraphicBlock<'a>
Source§fn clone(&self) -> GraphicBlock<'a>
fn clone(&self) -> GraphicBlock<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<'a> Debug for GraphicBlock<'a>
impl<'a> Debug for GraphicBlock<'a>
Source§impl<'a> PartialEq for GraphicBlock<'a>
impl<'a> PartialEq for GraphicBlock<'a>
Source§impl Widget for GraphicBlock<'_>
Backward compatibility implementation for the Widget
trait.
impl Widget for GraphicBlock<'_>
Backward compatibility implementation for the Widget
trait.
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
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)
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.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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