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: PointTop-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: PointWidth 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: PointView-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: StateState flags.
options: OptionsOption flags.
grow_mode: GrowModeGrow-mode flags.
drag_mode: DragModeDrag-mode flags.
event_mask: EventMaskWhich 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: HelpCtxThe 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
impl ViewState
Sourcepub fn new(bounds: Rect) -> Self
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.
Sourcepub fn get_bounds(&self) -> Rect
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.
Sourcepub fn get_extent(&self) -> Rect
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.
Sourcepub fn set_bounds(&mut self, bounds: Rect)
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.
Sourcepub fn move_to(&mut self, x: i32, y: i32)
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.
Sourcepub fn grow_to(&mut self, x: i32, y: i32)
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.
Sourcepub fn show(&mut self)
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).
Sourcepub fn hide(&mut self)
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.
Sourcepub fn set_cursor(&mut self, x: i32, y: i32)
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.
Sourcepub fn show_cursor(&mut self)
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.
Sourcepub fn hide_cursor(&mut self)
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.
Sourcepub fn block_cursor(&mut self)
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.
Sourcepub fn normal_cursor(&mut self)
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.
Sourcepub fn id(&self) -> Option<ViewId>
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.
Sourcepub fn get_help_ctx(&self) -> HelpCtx
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.
Trait Implementations§
impl Eq for ViewState
impl StructuralPartialEq for ViewState
Auto Trait Implementations§
impl Freeze for ViewState
impl RefUnwindSafe for ViewState
impl Send for ViewState
impl Sync for ViewState
impl Unpin for ViewState
impl UnsafeUnpin for ViewState
impl UnwindSafe for ViewState
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,
§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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.