pub struct Dialog {
id: Id,
rect: Rectangle,
children: Vec<Box<dyn View>>,
view_id: ViewId,
button_count: usize,
button_width: i32,
}Expand description
A modal dialog view that displays a message and allows users to select from custom buttons.
The dialog is centered on the display and renders a bordered rectangle containing:
- A title message (can be multi-line)
- Buttons evenly distributed horizontally
§Closing a Dialog
The dialog sends an Event::Close when the user taps outside the dialog area.
To close the dialog from a button tap, configure the button with a Event::Close event.
Other button events are propagated without closing the dialog. Which means you must handle the
closing of the dialog.
§Lifecycle
Create a dialog using the builder pattern via Dialog::builder, which handles
automatic layout calculation based on the display dimensions and text content.
§Example
use cadmus_core::view::dialog::Dialog;
use cadmus_core::view::{Event, ViewId, View};
let mut view_children: Vec<Box<dyn View>> = Vec::new();
// Note: In actual use, `context` is provided by the application.
// Dialog::builder requires a properly initialized Context with
// Display and Fonts, so we show the API pattern here.
let dialog = Dialog::builder(ViewId::BookMenu, "Delete this file?".to_string())
.add_button("No", Event::Close(ViewId::BookMenu))
.add_button("Yes", Event::Close(ViewId::BookMenu))
.build(&mut context);
view_children.push(Box::new(dialog) as Box<dyn View>);Fields§
§id: Id§rect: Rectangle§children: Vec<Box<dyn View>>§view_id: ViewIdContent-based button width computed once during DialogBuilder::build
from the widest button text. Reused by layout_children
on every resize so buttons keep their text-proportional sizing.
Implementations§
Source§impl Dialog
impl Dialog
Sourcepub fn builder(view_id: ViewId, title: String) -> DialogBuilder
pub fn builder(view_id: ViewId, title: String) -> DialogBuilder
Create a builder for a new dialog.
§Arguments
view_id- Unique identifier for the dialogtitle- The message text to display (supports multi-line text)
§Returns
A DialogBuilder that can be configured with buttons via add_button.
§Example
use cadmus_core::view::dialog::Dialog;
use cadmus_core::view::{Event, ViewId};
let _dialog = Dialog::builder(ViewId::BookMenu, "Are you sure?".to_string())
.add_button("Cancel", Event::Close(ViewId::BookMenu))
.add_button("OK", Event::Validate)
.build(&mut context);Sourcefn layout_children(&mut self, fonts: &mut Fonts)
fn layout_children(&mut self, fonts: &mut Fonts)
Position all child views within the current dialog rect.
Labels are stacked vertically with one padding inset from each edge.
Buttons use a content-based width (button_width)
and are centered horizontally with even spacing.
Both DialogBuilder::build and Dialog::resize delegate to this
method so the layout algorithm is defined in a single place.
Trait Implementations§
Source§impl View for Dialog
impl View for Dialog
fn handle_event( &mut self, evt: &Event, hub: &Hub, _bus: &mut Bus, _rq: &mut RenderQueue, _context: &mut Context, ) -> bool
fn render(&self, fb: &mut dyn Framebuffer, _rect: Rectangle, _fonts: &mut Fonts)
fn resize( &mut self, _rect: Rectangle, hub: &Hub, rq: &mut RenderQueue, context: &mut Context, )
fn is_background(&self) -> bool
fn rect(&self) -> &Rectangle
fn rect_mut(&mut self) -> &mut Rectangle
fn children(&self) -> &Vec<Box<dyn View>>
fn children_mut(&mut self) -> &mut Vec<Box<dyn View>>
fn id(&self) -> Id
fn view_id(&self) -> Option<ViewId>
fn render_rect(&self, _rect: &Rectangle) -> Rectangle
fn child(&self, index: usize) -> &dyn View
fn child_mut(&mut self, index: usize) -> &mut dyn View
fn len(&self) -> usize
fn might_skip(&self, _evt: &Event) -> bool
fn might_rotate(&self) -> bool
Auto Trait Implementations§
impl Freeze for Dialog
impl !RefUnwindSafe for Dialog
impl !Send for Dialog
impl !Sync for Dialog
impl Unpin for Dialog
impl !UnwindSafe for Dialog
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
§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>, which can then be
downcast into Box<dyn 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>, which 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.