Expand description
unstable
This crate is a part of rat-salsa.
§Rat Dialog
This crates provides a DialogStack that can be used with rat-salsa apps. It can stack and render any number of dialog-windows on top of the main application.
It uses the rat-salsa traits for AppWidget/AppState for rendering and event handling.
use anyhow::Error;
use rat_dialog::DialogStackState;
use rat_dialog::widgets::{FileDialog, FileDialogState};
impl AppState<GlobalState, MyEvent, Error> for MyAppState {
fn event(
&mut self,
event: &MyEvent,
ctx: &mut rat_salsa::AppContext<'_, GlobalState, MyEvent, Error>,
) -> Result<Control<MyEvent>, Error> {
if matches!(event, MyEvent::Event(event)) {
ctx.g.dialogs.push_dialog(
|_, ctx| {
Box::new(FileDialog::new().styles(ctx.g.theme.file_dialog_style()))
},
FileDialogState::new()
.save_dialog_ext(PathBuf::from("."), "", "pas")?
.map_outcome(|r| match r {
FileOutcome::Ok(f) => {
Control::Event(MyEvent::Status(0, format!("New file {:?}", f)))
}
r => r.into(),
}),
);
Ok(Control::Changed)
} else {
Ok(Control::Continue)
}
}
}
During rendering of the application:
use rat_dialog::{DialogStack, DialogStackState};
impl AppWidget<GlobalState, MyEvent, Error> for MainApp {
type State = MainAppState;
fn render(
&self,
area: Rect,
buf: &mut Buffer,
state: &mut Self::State,
ctx: &mut RenderContext<'_, GlobalState>,
) -> Result<(), Error> {
// ... do all the rendering ...
DialogStack.render(area, buf, &mut ctx.g.dialogs.clone(), ctx)?;
Ok(())
}
}
Modules§
Structs§
- Dialog
Stack - DialogStack.
- Dialog
Stack State - State of the dialog stack.
Enums§
- Dialog
Stack Error - Errors for some operations.
Traits§
- Dialog
State - Trait for a dialogs state.
- Dialog
Widget - DialogWidget mimics AppWidget.