Struct arkham::prelude::ViewContext
source · pub struct ViewContext {
pub view: View,
pub container: Rc<RefCell<Container>>,
/* private fields */
}
Expand description
ViewContext represents the display context for a given area. it maintains the drawing state for the region internally and is used to generate a final view that is eventually rendered.
Fields§
§view: View
§container: Rc<RefCell<Container>>
Implementations§
source§impl ViewContext
impl ViewContext
sourcepub fn new(container: Rc<RefCell<Container>>, size: Size) -> Self
pub fn new(container: Rc<RefCell<Container>>, size: Size) -> Self
Constructs a new ViewConext for a given area. A container reference must also be passedo, so that component functions called from the context are injectable.
sourcepub fn render(&mut self)
pub fn render(&mut self)
Notify the application to rerender the view. This is useful after a state change that might affect other views.
Examples found in repository?
examples/navigation.rs (line 34)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn main_route(ctx: &mut ViewContext, kb: Res<Keyboard>, route: State<Route>) {
ctx.insert(
0,
"Welcome to the main screen, press 2 to goto the secondary screen",
);
if kb.char() == Some('2') {
*route.get_mut() = Route::Secondary;
ctx.render();
}
}
fn secondary_route(ctx: &mut ViewContext, kb: Res<Keyboard>, route: State<Route>) {
ctx.insert(
0,
"Welcome to the secondary screen, press 1 to goto the main screen",
);
if kb.char() == Some('1') {
*route.get_mut() = Route::Main;
ctx.render();
}
}
sourcepub fn vertical_stack<S>(&self, size: S) -> Stack
pub fn vertical_stack<S>(&self, size: S) -> Stack
sourcepub fn horizontal_stack<S>(&self, size: S) -> Stack
pub fn horizontal_stack<S>(&self, size: S) -> Stack
sourcepub fn component<F, Args, R>(&mut self, rect: R, f: F)
pub fn component<F, Args, R>(&mut self, rect: R, f: F)
Execute a component function. The passed function will receive a new ViewContext for its size and can be injected with arguments. The context given to the component function will then be applied to the parent ViewContext at a given position.
Examples found in repository?
examples/stack.rs (line 12)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
fn root(ctx: &mut ViewContext) {
let mut stack = ctx.vertical_stack((100, 100));
for _ in 0..10 {
stack.component((ctx.size().width, 1), list_item);
}
ctx.component((0, (100, 100)), stack);
}
fn list_item(ctx: &mut ViewContext) {
let size = ctx.size();
let mut hstack = ctx.horizontal_stack((ctx.size().width, 1));
hstack.insert("> ");
hstack.insert("line 1");
ctx.component(size, hstack);
}
More examples
examples/navigation.rs (line 19)
13 14 15 16 17 18 19 20 21 22 23 24 25
fn root(ctx: &mut ViewContext, route: State<Route>) {
let size = ctx.size();
let r = *route.get();
ctx.insert((0, 0), "Press Q to quit");
match r {
Route::Main => {
ctx.component(Rect::new((0, 1), size), main_route);
}
Route::Secondary => {
ctx.component(Rect::new((0, 1), size), secondary_route);
}
}
}
Trait Implementations§
source§impl Deref for ViewContext
impl Deref for ViewContext
Auto Trait Implementations§
impl Freeze for ViewContext
impl !RefUnwindSafe for ViewContext
impl !Send for ViewContext
impl !Sync for ViewContext
impl Unpin for ViewContext
impl !UnwindSafe for ViewContext
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more