Guide API
Skip to main content

DrawCtx

Struct DrawCtx 

Source
pub struct DrawCtx<'a> { /* private fields */ }
Expand description

The clipped, themed writer every view paints through.

All public write methods take view-local coordinates: (0, 0) is the view’s own top-left. The ctx adds origin to translate into absolute screen columns/rows, and clips every write to clip. The clip is stored as an absolute rect already intersected with the buffer bounds at construction, so a write can never index the buffer out of range.

§Turbo Vision heritage

The successor to TDrawBuffer plus the owner-relative coordinate math in TView::writeLine/writeBuf (tvwrite.cpp). A view receives this context downward instead of reaching up through an owner pointer (deviation D3).

Implementations§

Source§

impl<'a> DrawCtx<'a>

Source

pub fn new( buffer: &'a mut Buffer, theme: &'a Theme, clip: Rect, origin: Point, ) -> Self

Build a draw context.

clip is intersected with the buffer’s bounds ((0, 0, width, height)) at construction and stored absolute, so the write methods can never index out of bounds.

Source

pub fn style(&self, role: Role) -> Style

Look up the Style (foreground + background + modifiers) for role from the active theme.

Call this inside View::draw to obtain the correct color pair for a semantic role (Role::Background, Role::MenuSelected, etc.) and pass the result to put_char / put_str / fill. Using roles rather than hard-coded colors lets the whole application switch themes without touching widget code.

Source

pub fn owner_active(&self) -> bool

Whether the owning pane is the focused one (see DrawCtx owner_active).

Source

pub fn content_surface( &self, roles: SurfaceRoles, self_focused: bool, selectable: bool, ) -> Style

Select a focusable content widget’s surface per the three-surface rule: owner_active recede x own-focus well-vs-surface x selectability. surface means “a selectable sibling won the focus contest”, so a widget that can never hold focus (selectable == false) paints normal in an active pane, never surface. Under classic_blue every triple collapses to normal’s colour, preserving classic per-window uniformity; a theme opts into sibling distinction by giving surface its own colour.

Source

pub fn set_owner_active(&mut self, v: bool)

Set the owning-pane-active flag for this context. Called by Group::draw.

Source

pub fn glyphs(&self) -> &Glyphs

The theme’s glyph holder.

Source

pub fn clip(&self) -> Rect

The absolute clip rect for this draw pass (already intersected with the buffer bounds at construction).

Use this inside View::draw when a widget wants to skip drawing rows or columns that are entirely outside the clip — for example, to avoid iterating over a large list’s invisible rows. All DrawCtx write methods already clip automatically, so querying this rect is an optimization, not a correctness requirement. The rect is in absolute screen coordinates, not view-local.

Source

pub fn origin(&self) -> Point

The absolute screen position that view-local (0, 0) maps to.

Source

pub fn screen_size(&self) -> Point

The size of the whole screen buffer (the root group’s size), for placing a popup_menu from a nested view.

Source

pub fn put_char(&mut self, x: i32, y: i32, ch: char, style: Style)

Write one cell at view-local (x, y) with style.

A double-width ch sets the lead wide and the next cell wide_trail, but only if both fall inside the clip; if the trail would fall outside, a space is written instead. Anything fully outside the clip is dropped (never panics).

Source

pub fn put_str(&mut self, x: i32, y: i32, s: &str, style: Style) -> i32

Write s at view-local (x, y) with a fixed style, width-aware and clipped. Returns the number of columns actually written.

Delegates the wide-char and edge-straddle logic to text::draw_str, exactly as DrawBuffer::move_str_part does — the string is written into the clipped sub-slice of the target buffer row, with indent / text_indent chosen so a glyph straddling either clip edge degrades the same way move_str_part already handles it.

Source

pub fn put_str_part( &mut self, x: i32, y: i32, s: &str, text_indent: i32, style: Style, ) -> i32

Write s at view-local (x, y) with a fixed style, starting from display column text_indent of s (skipping that many leading columns) — used to render a horizontally-scrolled input field. Width-aware and clipped exactly like put_str. Returns columns written.

A glyph straddling the text_indent boundary degrades to a space (the move_str_part left-edge straddle), via text::draw_str.

Source

pub fn put_cstr(&mut self, x: i32, y: i32, s: &str, lo: Style, hi: Style) -> i32

Write s at view-local (x, y), toggling between lo and hi styles at each ~ (the ~ itself is not drawn) — the attribute-pair toggle used by frame icons and reused by buttons/labels/menus for hotkey highlighting. Starts in lo. Clipped exactly like put_char. Returns the number of columns advanced.

Faithful to DrawBuffer::move_cstr_part: the first ~ flips lo → hi, the next flips back, and so on; the ~ characters draw nothing and do not advance the column.

Source

pub fn fill(&mut self, area_local: Rect, ch: char, style: Style)

Fill view-local rect area_local (clipped) with ch styled style.

Source

pub fn cast_shadow(&mut self, area_local: Rect)

Cast a drop shadow for the view at view-local rect area_local.

The shadow region is (area_local translated by SHADOW_SIZE) minus area_local — the classic offset-L: a 2-column strip down the right edge (starting 1 row below the top, extending 1 row past the bottom) plus a 1-row strip along the bottom (starting 2 columns right of the left edge). Each cell in the region (clipped to self.clip) keeps its glyph and gets the shadow attribute: the theme’s Role::Shadow style, or its reversed form when the cell’s background is black (so the shadow stays visible on black). Cells already marked no_shadow are left untouched (no double-shadow where two shadows overlap); transformed cells get no_shadow = true. The cell’s own style modifiers survive — the recolor re-applies the original style word onto the shadow attribute.

Under whole-tree redraw the buffer is reset each frame, so no_shadow markers never go stale; later (higher) siblings simply paint over the shadow cells they occlude.

§Turbo Vision heritage

Ports the shadow pass applyShadow (tvwrite.cpp); the on-black reverse is reverseAttribute(shadowAttr) and the modifier-preserving recolor is setStyle(attr, style | slNoShadow).

Source

pub fn sub(&mut self, area_local: Rect) -> DrawCtx<'_>

A child context for a sub-view at view-local rect area_local.

The child’s clip is self.clip ∩ (area_local translated by origin), and its origin is self.origin + area_local.a. The buffer is reborrowed for the child’s shorter lifetime. No re-intersection with the buffer bounds is needed — self.clip is already inside them.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for DrawCtx<'a>

§

impl<'a> Freeze for DrawCtx<'a>

§

impl<'a> RefUnwindSafe for DrawCtx<'a>

§

impl<'a> Send for DrawCtx<'a>

§

impl<'a> Sync for DrawCtx<'a>

§

impl<'a> Unpin for DrawCtx<'a>

§

impl<'a> UnsafeUnpin for DrawCtx<'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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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.