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>
impl<'a> DrawCtx<'a>
Sourcepub fn new(
buffer: &'a mut Buffer,
theme: &'a Theme,
clip: Rect,
origin: Point,
) -> Self
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.
Sourcepub fn style(&self, role: Role) -> Style
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.
Sourcepub fn owner_active(&self) -> bool
pub fn owner_active(&self) -> bool
Whether the owning pane is the focused one (see DrawCtx owner_active).
Sourcepub fn content_surface(
&self,
roles: SurfaceRoles,
self_focused: bool,
selectable: bool,
) -> Style
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.
Sourcepub fn set_owner_active(&mut self, v: bool)
pub fn set_owner_active(&mut self, v: bool)
Set the owning-pane-active flag for this context. Called by Group::draw.
Sourcepub fn clip(&self) -> Rect
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.
Sourcepub fn screen_size(&self) -> Point
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.
Sourcepub fn put_char(&mut self, x: i32, y: i32, ch: char, style: Style)
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).
Sourcepub fn put_str(&mut self, x: i32, y: i32, s: &str, style: Style) -> i32
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.
Sourcepub fn put_str_part(
&mut self,
x: i32,
y: i32,
s: &str,
text_indent: i32,
style: Style,
) -> i32
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.
Sourcepub fn put_cstr(&mut self, x: i32, y: i32, s: &str, lo: Style, hi: Style) -> i32
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.
Sourcepub fn fill(&mut self, area_local: Rect, ch: char, style: Style)
pub fn fill(&mut self, area_local: Rect, ch: char, style: Style)
Fill view-local rect area_local (clipped) with ch styled style.
Sourcepub fn cast_shadow(&mut self, area_local: Rect)
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).
Sourcepub fn sub(&mut self, area_local: Rect) -> DrawCtx<'_>
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> 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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.