Skip to main content

Controller

Struct Controller 

Source
pub struct Controller {
    pub down: HashSet<Key>,
    pub buttons: u8,
}
Expand description

Main controller device for the Varvara system.

Fields§

§down: HashSet<Key>

Keys that are currently held down

§buttons: u8

Current button state

Implementations§

Source§

impl Controller

Source

pub fn new() -> Self

Builds a new controller with no keys held

Source

pub fn char(&mut self, vm: &mut Uxn<'_>, c: u8) -> Event

Sends a single character event

Source

pub fn pressed( &mut self, vm: &mut Uxn<'_>, k: Key, repeat: bool, ) -> Option<Event>

Send the given key event, returning an event if needed

Source

pub fn released(&mut self, vm: &mut Uxn<'_>, k: Key) -> Option<Event>

Indicate that the given key has been released

This may change our button state and return an event

Source

pub fn check_buttons(&mut self, vm: &mut Uxn<'_>, repeat: bool) -> Option<Event>

Checks the current button states and returns an event if any button state changed.

Trait Implementations§

Source§

impl ControllerDevice for Controller

Source§

fn as_any(&mut self) -> &mut dyn Any

Returns a mutable reference to self as Any for downcasting.
Source§

fn char(&mut self, vm: &mut Uxn<'_>, c: u8) -> Event

Handles a character input event.
Source§

fn pressed(&mut self, vm: &mut Uxn<'_>, k: Key, repeat: bool) -> Option<Event>

Handles a key press event.
Source§

fn released(&mut self, vm: &mut Uxn<'_>, k: Key) -> Option<Event>

Handles a key release event.
Source§

impl Default for Controller

Source§

fn default() -> Controller

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.