Skip to main content

Canvas

Struct Canvas 

Source
pub struct Canvas { /* private fields */ }
Expand description

The interface of one frame plus what the player did with the previous one.

Implementations§

Source§

impl Canvas

Source

pub fn width(&self) -> f32

Width of the virtual screen (720 high, width follows the window).

Source

pub fn set_style(&self, style: ButtonStyle)

Sets the look of the following buttons and sliders.

Source

pub fn style(&self) -> ButtonStyle

The current button style.

Source

pub fn panel(&self, rect: [f32; 4], color: [f32; 4], radius: f32)

A filled panel.

Source

pub fn frame( &self, rect: [f32; 4], color: [f32; 4], outline: [f32; 4], radius: f32, )

A panel with an outline.

Source

pub fn text( &self, text: &str, pos: [f32; 2], size: f32, color: [f32; 4], font: &str, align: Align, )

One line (or a wrapped paragraph when wrap > 0 is given via Self::paragraph) of text.

Source

pub fn paragraph( &self, text: &str, pos: [f32; 2], width: f32, size: f32, color: [f32; 4], font: &str, )

Text wrapped to width units.

Source

pub fn image(&self, path: &str, rect: [f32; 4], tint: [f32; 4])

An image (PNG/JPG from the assets).

Source

pub fn button(&self, id: &str, rect: [f32; 4], text: &str) -> bool

A button; returns true on the frame after it was clicked.

Source

pub fn hovered(&self, id: &str) -> bool

Whether the pointer was over the button last frame.

Source

pub fn slider(&self, id: &str, rect: [f32; 4], value: f32) -> f32

A slider showing value (0..1); returns the value after the player’s change.

Source

pub fn toggle(&self, id: &str, rect: [f32; 4], label: &str, on: bool) -> bool

A toggle drawn as a button with ON / OFF; returns the new state.

Source

pub fn mouse(&self) -> [f32; 2]

Mouse position in interface units.

Source

pub fn commands(&self) -> Vec<UiCmd>

Commands of the current frame.

Source

pub fn wants_mouse(&self) -> bool

Whether any interactive element is on screen (the host then shows the cursor).

Source

pub fn begin(&self)

Starts a new frame of commands (called by the runtime before scripts update).

Source

pub fn feedback( &self, clicked: Vec<String>, hovered: Vec<String>, changed: Vec<(String, f32)>, width: f32, mouse: [f32; 2], )

What the player did with the painted frame (called by the shell after painting).

Trait Implementations§

Source§

impl Clone for Canvas

Source§

fn clone(&self) -> Canvas

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Canvas

Source§

fn default() -> Canvas

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

Auto Trait Implementations§

§

impl !Freeze for Canvas

§

impl !RefUnwindSafe for Canvas

§

impl !Sync for Canvas

§

impl Send for Canvas

§

impl Unpin for Canvas

§

impl UnsafeUnpin for Canvas

§

impl UnwindSafe for Canvas

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.