Struct ModalSheet
pub struct ModalSheet { /* private fields */ }Expand description
The immediate-mode sheet for a painted host that keeps its own state (a
question with three answers, a confirmation over a canvas): it lays the
sheet out, paints it with hover, press and keyboard focus on its
actions, keeps the layout of its last paint for hit-testing, and turns
input into a SheetResponse. The host paints only its body.
// draw_overlay:
let window = presence.viewport.get().unwrap_or(self.rect);
let spec = ModalSpec::new("Save changes to notes.md?").actions(&[
ModalAction::primary("Save"),
ModalAction::alternate_danger("Don't save"),
ModalAction::secondary("Cancel"),
]);
self.sheet.paint_message(scene, transform, text, theme, window, &spec, "Your changes will be lost.");
// handle_event:
match self.sheet.handle(event, ctx.scale_factor) {
Some(SheetResponse::Action(0)) => self.save(),
Some(SheetResponse::Action(1)) => self.discard(),
Some(SheetResponse::Action(_) | SheetResponse::Dismiss) => self.cancel(),
None => {}
}
*ctx.handled = true;Implementations§
§impl ModalSheet
impl ModalSheet
pub fn new() -> ModalSheet
pub fn reset(&mut self)
pub fn reset(&mut self)
Forget the last paint and any focus: call when the sheet closes, so the next question starts fresh.
pub fn layout(&self) -> Option<&ModalLayout>
pub fn layout(&self) -> Option<&ModalLayout>
The geometry of the last paint, for hit-testing without a renderer.
pub fn message_height(
text_renderer: &mut TextRenderer,
theme: &Theme,
window: Rect,
max_width: f64,
message: &str,
) -> f64
pub fn message_height( text_renderer: &mut TextRenderer, theme: &Theme, window: Rect, max_width: f64, message: &str, ) -> f64
Height a plain message takes as the body of a sheet in window.
pub fn paint_message(
&mut self,
scene: &mut Scene,
transform: Affine,
text_renderer: &mut TextRenderer,
theme: &Theme,
window: Rect,
spec: &ModalSpec<'_>,
message: &str,
)
pub fn paint_message( &mut self, scene: &mut Scene, transform: Affine, text_renderer: &mut TextRenderer, theme: &Theme, window: Rect, spec: &ModalSpec<'_>, message: &str, )
Paint the sheet for spec over window with message as its body,
in secondary ink. The body height is measured here.
pub fn paint(
&mut self,
scene: &mut Scene,
transform: Affine,
text_renderer: &mut TextRenderer,
theme: &Theme,
window: Rect,
spec: &ModalSpec<'_>,
body: impl FnOnce(&mut Scene, Affine, &mut TextRenderer, &Theme, Rect),
)
pub fn paint( &mut self, scene: &mut Scene, transform: Affine, text_renderer: &mut TextRenderer, theme: &Theme, window: Rect, spec: &ModalSpec<'_>, body: impl FnOnce(&mut Scene, Affine, &mut TextRenderer, &Theme, Rect), )
Paint the sheet for spec over window, calling body to draw the
host’s content inside the body rect (spec.body_height tall). The
actions show this sheet’s hover, press and focus.
pub fn handle(
&mut self,
event: &WindowEvent,
scale_factor: f64,
) -> Option<SheetResponse>
pub fn handle( &mut self, event: &WindowEvent, scale_factor: f64, ) -> Option<SheetResponse>
Route event to the sheet. Returns what it was answered with; the
host consumes every event while the sheet is up either way.
pub fn focused_action(&self) -> Option<usize>
pub fn focused_action(&self) -> Option<usize>
The action keyboard focus is on, if any.
Trait Implementations§
§impl Clone for ModalSheet
impl Clone for ModalSheet
§fn clone(&self) -> ModalSheet
fn clone(&self) -> ModalSheet
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for ModalSheet
impl Debug for ModalSheet
§impl Default for ModalSheet
impl Default for ModalSheet
§fn default() -> ModalSheet
fn default() -> ModalSheet
Auto Trait Implementations§
impl Freeze for ModalSheet
impl RefUnwindSafe for ModalSheet
impl Send for ModalSheet
impl Sync for ModalSheet
impl Unpin for ModalSheet
impl UnsafeUnpin for ModalSheet
impl UnwindSafe for ModalSheet
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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