Skip to content

struct

Event

pub struct Event {
    pub kind: String,
    pub value: Option<String>,
    pub key: Option<String>,
    pub x: f32,
    pub y: f32,
    pub dom: BTreeMap<String, Value>,
    pub index: Option<usize>,
    pub item: Option<Value>,
    pub args: Vec<Value>,
}

A UI event. Hosts fill in what they know; handlers bound inside a for loop also receive the loop index and item.

Fields

kind

pub kind: String

The event's name: click, input, keydown…

value

pub value: Option<String>

Current value of an input, if any.

key

pub key: Option<String>

The key pressed, for keyboard events (Enter, a…).

x

pub x: f32

Pointer position relative to the target element.

y

pub y: f32

See x.

dom

pub dom: BTreeMap<String, Value>

The browser event's own plain values, by their DOM names (deltaX, clientX, shiftKey, pointerType…): every number, text and true/false it has, as MDN documents them. Empty off the browser. Weft's own fields win where a name is the same (x, y, key).

index

pub index: Option<usize>

The loop index, for handlers bound inside a for.

item

pub item: Option<Value>

The loop item, for handlers bound inside a for.

args

pub args: Vec<Value>

What a handler call passed (@click: remove(t.id)), for the handler's parameters.

Methods

new

pub fn new(kind: &str) -> Event

An event of kind ("click", "input"…) with nothing else set.

with_value

pub fn with_value(self, value: impl Into<String>) -> Event

The event with value set: a control's value, or what a component emits.

with_position

pub fn with_position(self, x: f32, y: f32) -> Event

The event with the pointer at x, y.

with_key

pub fn with_key(self, key: impl Into<String>) -> Event

The event with key set ("Enter").

with_dom

pub fn with_dom(self, dom: BTreeMap<String, Value>) -> Event

The event with the browser event's plain values (see [Event::dom]).

with_args

pub fn with_args(self, args: Vec<Value>) -> Event

The event with args: the values a handler's call passed (@click: remove(t.id)), for its parameters.

to_value

pub fn to_value(&self) -> Value

The event as a record, as handlers declared in templates see it (event.value, event.index, …).

with_item

pub fn with_item(self, index: usize, item: Value) -> Event

The event as it comes from inside a for loop: the item at index.

Trait implementations