Skip to main content

RenderCx

Struct RenderCx 

Source
pub struct RenderCx<'a> {
    pub rect: Rect,
    pub buffer: &'a mut Buffer,
    pub cursor: Pos,
    pub style: Style,
    pub focused_id: Option<NodeId>,
    pub clip_rect: Option<Rect>,
    pub wrap: TextWrap,
    pub truncate: TextTruncate,
    pub align: TextAlign,
}
Expand description

渲染上下文——组件通过它输出内容到缓冲区

Fields§

§rect: Rect§buffer: &'a mut Buffer§cursor: Pos§style: Style§focused_id: Option<NodeId>

当前焦点节点

§clip_rect: Option<Rect>

裁剪区域(覆盖 rect 的默认裁剪,用于 Scroll 等)

§wrap: TextWrap

文本换行模式

§truncate: TextTruncate

文本截断模式

§align: TextAlign

文本对齐

Implementations§

Source§

impl<'a> RenderCx<'a>

Source

pub fn new(rect: Rect, buffer: &'a mut Buffer, style: Style) -> Self

Source

pub fn is_focused(&self, id: NodeId) -> bool

检查指定节点是否为当前焦点

Source

pub fn align_offset(&self, text_width: u16) -> u16

计算对齐偏移(根据当前 align 设置和有效裁剪区域)

Source

pub fn text(&mut self, text: impl AsRef<str>)

在 cursor 位置写入文本,推进 x(考虑宽字符和截断)

Source

pub fn line(&mut self, text: impl AsRef<str>)

写入文本后将 cursor 移到下一行行首(支持换行和截断)

Source

pub fn set_style(&mut self, style: Style)

修改当前渲染样式

Source

pub fn draw_border(&mut self, border: Border)

绘制边框(使用当前样式,遵循 clip_rect)

Auto Trait Implementations§

§

impl<'a> Freeze for RenderCx<'a>

§

impl<'a> RefUnwindSafe for RenderCx<'a>

§

impl<'a> Send for RenderCx<'a>

§

impl<'a> Sync for RenderCx<'a>

§

impl<'a> Unpin for RenderCx<'a>

§

impl<'a> UnsafeUnpin for RenderCx<'a>

§

impl<'a> !UnwindSafe for RenderCx<'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> 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, 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.