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,
impl<F, Args> App<F, Args>where
F: Callable<Args>,
Args: FromContainer,
Sourcepub fn new(root: F) -> App<F, Args>
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?
More examples
Sourcepub fn get_renderer(&self) -> Renderer
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.
Sourcepub fn insert_resource<T: Any>(self, v: T) -> Self
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.
Sourcepub fn insert_state<T: Any>(self, v: T) -> Self
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));
}