Module dialog

Module dialog 

Source
Expand description

A modal dialog view that displays a message and custom buttons.

The dialog component provides a flexible way to display modal dialogs with a title message and multiple custom buttons. Dialogs are centered on the display and render with a bordered white background.

§Building a Dialog

Use the Dialog::builder method to create a dialog with a fluent API:

use cadmus_core::view::dialog::Dialog;
use cadmus_core::view::{Event, ViewId};

let dialog = Dialog::builder(ViewId::BookMenu, "Confirm deletion?".to_string())
    .add_button("Cancel", Event::Close(ViewId::BookMenu))
    .add_button("Delete", Event::Close(ViewId::BookMenu))
    .build(&mut context);

§Behavior

  • Multi-line messages: The title supports multi-line text via newline characters
  • Dynamic layout: Buttons are evenly distributed horizontally regardless of count
  • Button events: When a button is tapped, it sends the event configured for that button. To close the dialog, you can either make the button event an Event::Close or handle the event in your view logic to remove the dialog from the view hierarchy.
  • Outside tap: Tapping outside the dialog area automatically sends an Event::Close

§Example: Adding to a View

use cadmus_core::view::dialog::Dialog;
use cadmus_core::view::{Event, ViewId, View};

let dialog = Dialog::builder(ViewId::BookMenu, "Save changes?".to_string())
    .add_button("Discard", Event::Close(ViewId::BookMenu))
    .add_button("Save", Event::Close(ViewId::BookMenu))
    .build(&mut context);

// Add the dialog to your view hierarchy
view_children.push(Box::new(dialog) as Box<dyn View>);

Structs§

Dialog
A modal dialog view that displays a message and allows users to select from custom buttons.
DialogBuilder
Builder for constructing a Dialog with custom buttons and message.