Struct intuitive::components::experimental::modal::Modal
source · pub struct Modal {
pub children: Children<1>,
pub on_key: KeyHandler,
}
Available on crate feature
experimental
only.Expand description
A component supporting modal-style overlays.
The Modal
component allows a user to present a Component
on top of
the children of the modal, from anywhere inside it. This is useful for popups such
as input boxes, or error messages.
For example, if we wanted to show an error message
whenever the Enter
key is pressed, we can do something like this:
#[component(MyComponent)]
fn render() {
let modal = use_modal();
let on_key = on_key! {
KeyEvent { code: Enter, .. } => modal.show(render! {
Centered() {
Section(title: "Error", border: Color::Red) {
Text(text: "Enter was pressed!")
}
}
}),
KeyEvent { code: Esc, .. } if modal.is_shown() => modal.hide(),
KeyEvent { code: Esc, .. } => event::quit(),
};
render! {
Section(title: "Some Example UI", on_key)
}
}
#[component(Root)]
fn render() {
render! {
Modal() {
MyComponent()
}
}
}
In order to overlay an error message on top of MyComponent
, we render it
as a child of a Modal
. Then, in any descendant of this Modal
, we can call
use_modal
to mutate the state of that Modal
.
Internals
The Modal
is somewhat special in that it does not (yet) use the built-in
use_state
hooks, but instead has its own internal static
hook manager.
Fields§
§children: Children<1>
§on_key: KeyHandler
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Modal
impl Send for Modal
impl Sync for Modal
impl Unpin for Modal
impl !UnwindSafe for Modal
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