UserInterface

Struct UserInterface 

Source
pub struct UserInterface {
    pub assets: Assets,
    pub state: State,
    pub controller: Controller,
    pub keymap: Keymap,
    pub canvas: Canvas,
    /* private fields */
}
Expand description

Defines the user interface.

Fields§

§assets: Assets§state: State§controller: Controller§keymap: Keymap§canvas: Canvas

Implementations§

Source§

impl UserInterface

Source

pub fn new<T, C>(games: T, controller: C, keymap: Keymap) -> Self
where T: IntoIterator<Item = Box<dyn Game>>, C: Into<Controller>,

Creates the initial user interface state.

Source

pub fn draw(&self)

Draws the current state of the user interface.

Source

pub fn min_hex_diameter(&self) -> f64

Returns the minimum allowed hex diameter, which limits zooming out.

Source

pub fn max_hex_diameter(&self) -> f64

Returns the maximum allowed hex diameter, which limits zooming in.

Source

pub fn handle_key_press(&mut self, event: &KeyPress) -> UiResponse

Source

pub fn handle_button_press(&mut self, event: &ButtonPress) -> UiResponse

Source

pub fn respond(&mut self, response: UiResponse)

Source

pub fn map_size(&self) -> (i32, i32)

Returns the dimensions of the current game map, in pixels.

Source

pub fn zoom_and_redraw(&mut self)

Requests the drawing area to update its size, and redraws the current game state.

This should be called when the user has zoomed in or zoomed out.

Source

pub fn reset_and_redraw(&mut self)

Resets the drawing surface, requests the drawing area to update its size, and redraws the current game state.

This should only be called when the active game has changed (e.g., when creating a new game or loading a saved game).

Source

pub fn set_default_title(&mut self)

Sets the window title to the game name, replacing any state-specific title.

Source

pub fn ping(&mut self, dest: PingDest) -> UiResponse

Responds to an event triggered by something other than a UI event (e.g., a message from a task running in a separate thread).

Source

pub fn new_game(&mut self, game_ix: usize) -> UiResponse

Creates a new game, identified by index into the game library.

Source

pub fn load_game(&mut self, path: PathBuf) -> UiResponse

Loads a saved game state from path.

Source

pub fn save_game(&mut self, path: PathBuf) -> UiResponse

Saves the current game state to path.

Source

pub fn save_image(&self, path: PathBuf, image: ImageSurface) -> UiResponse

Saves an image to path.

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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.