Guide API
Skip to main content

ViewState

Struct ViewState 

Source
pub struct ViewState {
    pub origin: Point,
    pub size: Point,
    pub cursor: Point,
    pub state: State,
    pub options: Options,
    pub grow_mode: GrowMode,
    pub drag_mode: DragMode,
    pub event_mask: EventMask,
    pub help_ctx: HelpCtx,
    /* private fields */
}
Expand description

The data every view owns — origin, size, cursor, state/option/grow/drag flags, owner id, and more.

Widgets embed a ViewState (typically as a field named state) and reach its flags/geometry directly (self.state.state.focused, self.state.size). The data fields are pub; only resize_balance (the resize rounding-recovery accumulator) and id (stamped by Group::insert — write-once, enforced by pub(crate)) are not public.

Do not derive(Default) — the all-false derive would leave the view invisible with no drag limit, a silent bug. Construct via ViewState::new (or Default, which forwards to it with an empty rect).

§Turbo Vision heritage

Holds TView’s data members (tview.cpp/views.h). Composing this struct into each widget replaces inheriting those fields (deviation D2); the packed flag words become structs-of-bools (deviation D5).

Fields§

§origin: Point

Top-left corner of the view in its owner’s coordinate space.

Read this when you need the view’s owner-relative position (e.g. to compute sibling offsets). Write via set_bounds or move_to — never set the field directly inside View::change_bounds, which calls those helpers.

§size: Point

Width and height of the view (x = columns, y = rows).

Together with origin this defines the view’s bounds in owner space. Read it via get_bounds / get_extent; set via set_bounds or grow_to.

§cursor: Point

View-local hardware-cursor position (column, row) within this view.

Set via set_cursor. It is only shown when both State::cursor_vis is true and the view is focused; the event loop reads this field and places the hardware cursor in absolute coordinates (the loop knows the tree; a leaf does not). Reading the field directly is fine; prefer View::cursor_request when you need the loop-side absolute-cursor logic.

§state: State

State flags.

§options: Options

Option flags.

§grow_mode: GrowMode

Grow-mode flags.

§drag_mode: DragMode

Drag-mode flags.

§event_mask: EventMask

Which opt-in event classes this view wants. The always-delivered classes (mouse-down, key-down, command) are unconditional rather than opt-in, so only the mouse-move / auto-repeat opt-ins survive here.

§help_ctx: HelpCtx

The help context for status-line switching while this view is focused.

Set during construction (e.g. state.help_ctx = HelpCtx::custom("myapp.topic")). The value HelpCtx::NO_CONTEXT (the ctor default) means no context is provided; the status line typically falls back to the owner’s context in that case. While the view is being dragged, get_help_ctx returns HelpCtx::DRAGGING regardless of this field.

Implementations§

Source§

impl ViewState

Source

pub fn new(bounds: Rect) -> Self

Construct view state for bounds, with the canonical view defaults.

Defaults: visible, the top-edge drag limit, no help context, everything else off. event_mask is all-false because the always-delivered classes (mouse-down, key-down, command) are unconditional rather than opt-in.

Source

pub fn get_bounds(&self) -> Rect

The view’s bounds in owner coordinates: { origin, origin + size }.

Use this whenever you need the half-open rect that describes where the view sits in its parent’s frame, e.g. for hit-testing or sibling-offset calculations. For the same rect anchored at (0, 0) (local frame), use get_extent instead.

Source

pub fn get_extent(&self) -> Rect

The view’s extent in its own local coordinates: { 0, 0, size.x, size.y }.

Use this inside View::draw to fill the whole view, clip child rects, or compute layout in view-local space. Because the origin is always (0, 0), there is no translation needed.

Source

pub fn set_bounds(&mut self, bounds: Rect)

Set the bounds: origin = bounds.a; size = bounds.b - bounds.a.

The low-level primitive used by move_to, grow_to, and ViewState::new. Call through View::change_bounds in normal use so that groups can propagate the resize to their children.

Source

pub fn move_to(&mut self, x: i32, y: i32)

Relocate the top-left to (x, y), keeping the size.

A low-level position change that updates only the bounds fields (no redraw, no size-limit clamp). Typically called from within a group’s layout pass or from View::change_bounds; the loop’s whole-tree repaint redraws the view at its new position automatically.

Source

pub fn grow_to(&mut self, x: i32, y: i32)

Keep the origin, set the size to (x, y).

A low-level size change symmetric with move_to: no redraw or size-limit clamp. Size-limit enforcement lives on the group (which calls View::size_limits before adjusting children); use View::change_bounds or the free function locate for the full path.

Source

pub fn show(&mut self)

Make the view visible (state.visible = true).

The plain field write; the loop’s whole-tree redraw picks up the change on the next pump. Call this inside a widget’s constructor or a layout pass. To show a view that is already inserted into a live group (so that sibling scroll bars track it), use Context::request_set_visible (deferred, runs the owner’s currency tail).

Source

pub fn hide(&mut self)

Make the view invisible (state.visible = false).

Like show: a plain field flip for use during construction or layout. To hide a view that is already inserted into a live group (and keep sibling bars in sync), use Context::request_set_visible.

Source

pub fn set_cursor(&mut self, x: i32, y: i32)

Move the cursor to view-local (x, y).

Call this inside draw or handle_event to position the insertion point (e.g. an input line moving the caret after editing). The cursor is only shown when the view is focused and State::cursor_vis is true; make both conditions hold with show_cursor. The event loop translates the view-local position to absolute screen coordinates using the tree — no manual offset is needed here.

Source

pub fn show_cursor(&mut self)

Make the hardware cursor visible while this view is focused.

Sets State::cursor_vis. The event loop places the cursor at the absolute screen position corresponding to cursor. Call once in your widget’s constructor (or just after set_cursor) if you want an insertion-point cursor; pair with block_cursor or normal_cursor to pick the shape.

Source

pub fn hide_cursor(&mut self)

Hide the hardware cursor while this view is focused.

Clears State::cursor_vis. The hardware cursor will not be shown even if the view is focused. Widgets that draw a cursor in software (e.g. by painting a highlighted cell) call this to suppress the hardware cursor.

Source

pub fn block_cursor(&mut self)

Switch the hardware cursor to block (insert / overwrite) shape.

Sets State::cursor_ins; normal_cursor clears it. Many input-line widgets switch between shapes depending on an insert mode toggle, calling this or normal_cursor on each toggle.

Source

pub fn normal_cursor(&mut self)

Switch the hardware cursor to the normal shape (on a terminal, the terminal’s own caret).

Clears State::cursor_ins. This is the default shape; call this after block_cursor when leaving insert mode.

Source

pub fn id(&self) -> Option<ViewId>

This view’s global identity, set by Group::insert when the view enters a group; None before insertion. NOT an up-pointer — it is the view’s own handle (like an ECS entity id), which lets a handler/loop address it by id.

Source

pub fn get_help_ctx(&self) -> HelpCtx

Returns the effective help context: HelpCtx::DRAGGING while the view is being dragged, otherwise help_ctx.

The status line calls this (via View::get_help_ctx) on the focused view to decide which help topic to display. Usually you read view.help_ctx directly; call this method only when you need the drag-override behavior included.

Source

pub fn set_flag(&mut self, flag: StateFlag, enable: bool)

Flip the State bool named by flag — the plain field write for each propagating StateFlag. The broadcast / propagation side effects live in View::set_state, not here.

Trait Implementations§

Source§

impl Clone for ViewState

Source§

fn clone(&self) -> ViewState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ViewState

Source§

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

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

impl Default for ViewState

Source§

fn default() -> Self

Empty-rect view state with the canonical defaults (visible, top-edge drag limit). Not a derive — the all-false derive would be a silent bug.

Source§

impl Eq for ViewState

Source§

impl PartialEq for ViewState

Source§

fn eq(&self, other: &ViewState) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ViewState

Auto Trait Implementations§

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> CustomValue for T
where T: Any + Debug,

Source§

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

Upcast Rc<Self> to Rc<dyn Any> so FieldValue::as_custom / FieldValue::value_as can downcast.
§

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.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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.