Guide API
Skip to main content

MenuView

Trait MenuView 

Source
pub trait MenuView: View {
    // Required methods
    fn mv(&self) -> &MenuViewState;
    fn mv_mut(&mut self) -> &mut MenuViewState;

    // Provided method
    fn get_item_rect(&self, _index: usize) -> Rect { ... }
}
Expand description

The shared interface a MenuBar and a MenuBox implement so menu navigation can treat them uniformly.

Item geometry (get_item_rect) and the draw layout are the two operations that differ between a horizontal bar and a vertical box; they must agree cell-for-cell, so they travel together. The passive shared logic (hot_key/update_menu_commands/handle_event) stays as free functions over &Menu/MenuViewState. Menu navigation reaches a bar or box through a MenuView reference.

§Turbo Vision heritage

Ports the abstract part of TMenuView (tmnuview.cpp/menus.h). The TMenuBar/TMenuBox subclassing becomes this trait the two concrete views implement (deviation D2).

Required Methods§

Source

fn mv(&self) -> &MenuViewState

Borrow the embedded MenuViewState.

Source

fn mv_mut(&mut self) -> &mut MenuViewState

Mutably borrow the embedded MenuViewState.

Provided Methods§

Source

fn get_item_rect(&self, _index: usize) -> Rect

The screen rect (view-local coordinates) of item index within this view.

Every concrete implementor must override this — the default returns an empty rect, which the session uses as a fallback but which will produce invisible hit-testing. MenuBar overrides it with a horizontal left-to-right accumulator; MenuBox overrides it with a closed-form y = 1 + index formula. Implement it so the returned rect matches the cells drawn by View::draw cell-for-cell: the session’s mouse hit-testing reads item rects to track which item the cursor is over.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§