App

Struct App 

Source
pub struct App<F, Args>
where F: Callable<Args>, Args: FromContainer,
{ /* private fields */ }
Expand description

The app is the core container for the application logic, resources, state, and run loop.

Setting up a basic application:

use arkham::prelude::*;

fn main() {
    App::new(root_view).run();
}

fn root_view(ctx: &mut ViewContext) {
    ctx.insert((2,2), "Hello World");
}

Implementations§

Source§

impl<F, Args> App<F, Args>
where F: Callable<Args>, Args: FromContainer,

Source

pub fn new(root: F) -> App<F, Args>

Constructs a new App objcet. This object uses a builder pattern and should be finalized with App::run(). which will start a blocking run loop and perform the initial screen setup and render.

Examples found in repository?
examples/stack.rs (line 4)
3fn main() {
4    let _ = App::new(root).run();
5}
More examples
Hide additional examples
examples/component_functions.rs (line 4)
3fn main() {
4    App::new(root).run().expect("couldnt launch app");
5}
examples/component_params.rs (line 4)
3fn main() {
4    App::new(root).run().expect("couldnt launch app");
5}
examples/keyboard.rs (line 4)
3fn main() {
4    App::new(root).run().expect("couldnt launch app");
5}
examples/simple.rs (line 4)
3fn main() {
4    App::new(root).run().expect("couldnt launch app");
5}
examples/navigation.rs (line 10)
9fn main() {
10    let _ = App::new(root).insert_state(Route::Main).run();
11}
Source

pub fn get_renderer(&self) -> Renderer

Returns a renderer that can signal the application to rerender. This renderer can be cloned and passed between threads.

Source

pub fn insert_resource<T: Any>(self, v: T) -> Self

Insert a resource which can be injected into component functions.

This resource can only be accessed immutably by reference. Interior mutability must be used for anything that requires an internal state.

Example:

use arkham::prelude::*;
struct MyResource {
  value: i32
}

fn main() {
    App::new(root).insert_resource(MyResource { value: 12 });
}

fn root(ctx: &mut ViewContext, thing: Res<MyResource>)  {
    ctx.insert(0,format!("Value is {}", thing.value));
}

Alternatively, App::insert_state can be used to insert a state object, that can be borrowed mutable.

Examples found in repository?
examples/theme.rs (line 5)
3fn main() {
4    App::new(root)
5        .insert_resource(Theme::default())
6        .run()
7        .expect("couldnt launch app");
8}
Source

pub fn insert_state<T: Any>(self, v: T) -> Self

Insert a stateful object that can be injected into component functions unlike App::insert_resource, this value can be borrowed mutably and is meant to store application state.

Example:

use arkham::prelude::*;
struct MyState {
  value: i32
}

fn main() {
    App::new(root).insert_state(MyState { value: 12 });
}

fn root(ctx: &mut ViewContext, thing: State<MyState>)  {
    thing.get_mut().value += 1;
    ctx.insert(0,format!("Value is {}", thing.get().value));
}
Examples found in repository?
examples/navigation.rs (line 10)
9fn main() {
10    let _ = App::new(root).insert_state(Route::Main).run();
11}
Source

pub fn run(&mut self) -> Result<()>

Executes the main run loop. This should be called to start the application logic.

This function will block while it reads events and performs render cycles.

Examples found in repository?
examples/stack.rs (line 4)
3fn main() {
4    let _ = App::new(root).run();
5}
More examples
Hide additional examples
examples/component_functions.rs (line 4)
3fn main() {
4    App::new(root).run().expect("couldnt launch app");
5}
examples/component_params.rs (line 4)
3fn main() {
4    App::new(root).run().expect("couldnt launch app");
5}
examples/keyboard.rs (line 4)
3fn main() {
4    App::new(root).run().expect("couldnt launch app");
5}
examples/simple.rs (line 4)
3fn main() {
4    App::new(root).run().expect("couldnt launch app");
5}
examples/navigation.rs (line 10)
9fn main() {
10    let _ = App::new(root).insert_state(Route::Main).run();
11}

Auto Trait Implementations§

§

impl<F, Args> Freeze for App<F, Args>
where F: Freeze,

§

impl<F, Args> !RefUnwindSafe for App<F, Args>

§

impl<F, Args> !Send for App<F, Args>

§

impl<F, Args> !Sync for App<F, Args>

§

impl<F, Args> Unpin for App<F, Args>
where F: Unpin, Args: Unpin,

§

impl<F, Args> !UnwindSafe for App<F, Args>

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.