Struct cursive::views::Canvas [−][src]
pub struct Canvas<T> { /* fields omitted */ }
Expand description
A blank view that forwards calls to closures.
You can use this view to easily draw your own interface.
Examples
use cursive_core::event::{Event, EventResult, Key};
use cursive_core::views::{Canvas, Dialog};
use unicode_width::UnicodeWidthStr; // To get the width of some text.
// Build a canvas around a string.
let state = String::new();
let canvas = Canvas::new(state)
.with_draw(|text: &String, printer| {
// Simply print our string
printer.print((0, 0), text);
})
.with_on_event(|text: &mut String, event| match event {
Event::Char(c) => {
text.push(c);
EventResult::Consumed(None)
}
Event::Key(Key::Enter) => {
let text = text.clone();
EventResult::with_cb(move |s| {
s.add_layer(Dialog::info(&text));
})
}
_ => EventResult::Ignored,
})
.with_required_size(|text, _constraints| (text.width(), 1).into());
Implementations
Sets the closure for draw(&Printer)
.
Sets the closure for draw(&Printer)
.
Chainable variant.
pub fn set_on_event<F>(&mut self, f: F) where
F: 'static + FnMut(&mut T, Event) -> EventResult,
pub fn set_on_event<F>(&mut self, f: F) where
F: 'static + FnMut(&mut T, Event) -> EventResult,
Sets the closure for on_event(Event)
.
pub fn with_on_event<F>(self, f: F) -> Canvas<T> where
F: 'static + FnMut(&mut T, Event) -> EventResult,
pub fn with_on_event<F>(self, f: F) -> Canvas<T> where
F: 'static + FnMut(&mut T, Event) -> EventResult,
Sets the closure for on_event(Event)
.
Chainable variant.
Sets the closure for required_size(Vec2)
.
Sets the closure for required_size(Vec2)
.
Chainable variant.
Sets the closure for layout(Vec2)
.
Sets the closure for layout(Vec2)
.
Chainable variant.
pub fn set_take_focus<F>(&mut self, f: F) where
F: 'static + FnMut(&mut T, Direction) -> Result<EventResult, CannotFocus>,
pub fn set_take_focus<F>(&mut self, f: F) where
F: 'static + FnMut(&mut T, Direction) -> Result<EventResult, CannotFocus>,
Sets the closure for take_focus(Direction)
.
pub fn with_take_focus<F>(self, f: F) -> Canvas<T> where
F: 'static + FnMut(&mut T, Direction) -> Result<EventResult, CannotFocus>,
pub fn with_take_focus<F>(self, f: F) -> Canvas<T> where
F: 'static + FnMut(&mut T, Direction) -> Result<EventResult, CannotFocus>,
Sets the closure for take_focus(Direction)
.
Chainable variant.
Sets the closure for needs_relayout()
.
Sets the closure for needs_relayout()
.
Chainable variant.
Sets the closure for call_on_any()
.
Sets the closure for call_on_any()
.
Chainable variant.
Sets the closure for important_area()
.
Sets the closure for important_area()
.
Chainable variant.
pub fn set_focus_view<F>(&mut self, f: F) where
F: 'static + FnMut(&mut T, &Selector<'_>) -> Result<EventResult, ViewNotFound>,
pub fn set_focus_view<F>(&mut self, f: F) where
F: 'static + FnMut(&mut T, &Selector<'_>) -> Result<EventResult, ViewNotFound>,
Sets the closure for focus_view()
.
pub fn with_focus_view<F>(self, f: F) -> Canvas<T> where
F: 'static + FnMut(&mut T, &Selector<'_>) -> Result<EventResult, ViewNotFound>,
pub fn with_focus_view<F>(self, f: F) -> Canvas<T> where
F: 'static + FnMut(&mut T, &Selector<'_>) -> Result<EventResult, ViewNotFound>,
Sets the closure for focus_view()
.
Chainable variant.
Trait Implementations
Draws the view with the given printer (includes bounds) and focus. Read more
Called when an event is received (key press, mouse event, …). Read more
Returns the minimum size the view requires with the given restrictions. Read more
Called once the size for this view has been decided. Read more
Attempt to give this view the focus. Read more
Should return true
if the view content changed since the last call
to layout()
. Read more
Moves the focus to the view identified by the given selector. Read more
What part of the view is important and should be visible? Read more
pub fn call_on_any(
&mut self,
selector: &Selector<'_>,
cb: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
pub fn call_on_any(
&mut self,
selector: &Selector<'_>,
cb: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
Runs a closure on the view identified by the given selector. Read more
Auto Trait Implementations
impl<T> !RefUnwindSafe for Canvas<T>
impl<T> !UnwindSafe for Canvas<T>
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn into_boxed_view(self) -> Box<dyn View + 'static, Global>ⓘ
pub fn into_boxed_view(self) -> Box<dyn View + 'static, Global>ⓘ
Returns a Box<View>
.
Wraps self
in a ResizedView
with the given size constraints.
Wraps self
into a fixed-size ResizedView
.
Wraps self
into a fixed-width ResizedView
.
Wraps self
into a fixed-width ResizedView
.
Wraps self
into a full-screen ResizedView
.
Wraps self
into a full-width ResizedView
.
Wraps self
into a full-height ResizedView
.
Wraps self
into a limited-size ResizedView
.
Wraps self
into a limited-width ResizedView
.
Wraps self
into a limited-height ResizedView
.
Wraps self
into a ResizedView
at least sized size
.
Wraps self
in a ResizedView
at least min_width
wide.
Wraps self
in a ResizedView
at least min_height
tall.
Wraps self
in a ScrollView
.
Calls the given closure and return the result. Read more
Calls the given closure on self
.