pub trait MockComponent {
    // Required methods
    fn view(&mut self, frame: &mut Frame<'_>, area: Rect);
    fn query(&self, attr: Attribute) -> Option<AttrValue>;
    fn attr(&mut self, attr: Attribute, value: AttrValue);
    fn state(&self) -> State;
    fn perform(&mut self, cmd: Cmd) -> CmdResult;
}
Expand description

A Mock Component represents a component which defines all the properties and states it can handle and represent and the way it should be rendered. It must also define how to behave in case of a Cmd (command). Despite that, it won’t define how to behave after an Event and it won’t send any Msg. The MockComponent is intended to be used as a reusable component to implement your application component.

§In practice

A real life example would be an Input field. The mock component is represented by the Input, which will define the properties (e.g. max input length, input type, …) and by its behaviour (e.g. when the user types ‘a’, ‘a’ char is added to input state).

In your application though, you may use a IpAddressInput which is the Component using the Input mock component. If you want more example, just dive into the examples/ folder in the project root.

Required Methods§

source

fn view(&mut self, frame: &mut Frame<'_>, area: Rect)

Based on the current properties and states, renders the component in the provided area frame. Render can also mutate the component state if this is required

source

fn query(&self, attr: Attribute) -> Option<AttrValue>

Query attribute of component properties.

source

fn attr(&mut self, attr: Attribute, value: AttrValue)

Set attribute to properties. query describes the name, while attr the value it’ll take

source

fn state(&self) -> State

Get current state from component

source

fn perform(&mut self, cmd: Cmd) -> CmdResult

Perform a command on the component. The command will may change the component state. The method returns the result of the command applied (what changed if any)

Implementors§