Skip to main content

ContextMenu

Trait ContextMenu 

Source
pub trait ContextMenu: Debug {
    // Required methods
    fn open(&mut self, ctx: &ClickContext) -> bool;
    fn close(&mut self);
    fn is_open(&self) -> bool;
    fn draw(&self, cmd_buf: &mut Vec<DrawCommand>, width: f32, height: f32);
    fn pointer_event(
        &mut self,
        width: f32,
        height: f32,
        event: PointerEvent,
    ) -> MenuEventResult;
    fn needs_repaint(&self) -> bool;
}
Expand description

The context menu opened by right-clicking the web view.

The core opens the menu with open when the web content is right-pressed; while the menu reports is_open, every pointer event over the window is routed to it before the chrome or the page. The menu renders above all other UI via draw.

Required Methods§

Source

fn open(&mut self, ctx: &ClickContext) -> bool

Requests the menu at the given click position.

Returns true when the menu opened (and consumed the click); implementations may return false to decline (e.g. no items apply).

Source

fn close(&mut self)

Closes the menu without running an action.

Source

fn is_open(&self) -> bool

Whether the menu is currently open.

Source

fn draw(&self, cmd_buf: &mut Vec<DrawCommand>, width: f32, height: f32)

Draws the open menu into cmd_buf in window coordinates.

Called every frame after the chrome so the menu paints on top of everything else. Implementations should emit nothing while closed.

Source

fn pointer_event( &mut self, width: f32, height: f32, event: PointerEvent, ) -> MenuEventResult

Dispatches a pointer event to the open menu.

Only called while the menu is open. Returning consumed keeps the event away from the chrome and the page.

Source

fn needs_repaint(&self) -> bool

Whether the menu changed its visual state since the last check.

Consumes the flag, like crate::engine::ui::custom_node::CustomNode::needs_repaint.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§