iced_dialog/
lib.rs

1//! Custom dialog for [`iced`](https://iced.rs)
2//!
3//! It's mostly the dialog from @frgp42's [Fluent Iced Gallery](https://github.com/frgp42/fluent_iced_gallery), but made into a "widget".
4
5pub mod dialog;
6pub use dialog::Dialog;
7use iced_widget::Button;
8use iced_widget::core;
9use iced_widget::text::IntoFragment;
10use iced_widget::{container, text};
11
12/// Creates a new [`Dialog`] with the given base and dialog content.
13pub fn dialog<'a, Message, Theme, Renderer>(
14    is_open: bool,
15    base: impl Into<core::Element<'a, Message, Theme, Renderer>>,
16    content: impl Into<core::Element<'a, Message, Theme, Renderer>>,
17) -> Dialog<'a, Message, Theme, Renderer>
18where
19    Renderer: 'a + core::Renderer + core::text::Renderer,
20    Theme: 'a + dialog::Catalog,
21    Message: 'a + Clone,
22    <Theme as container::Catalog>::Class<'a>:
23        From<container::StyleFn<'a, Theme>>,
24{
25    Dialog::new(is_open, base, content)
26}
27
28/// Pre-styled [`Button`] for [`Dialog`]s.
29///
30/// [`Button`]: https://docs.iced.rs/iced/widget/struct.Button.html
31pub fn button<'a, Message, Theme, Renderer>(
32    content: impl IntoFragment<'a>,
33    message: Message,
34) -> Button<'a, Message, Theme, Renderer>
35where
36    Theme: 'a + iced_widget::button::Catalog + text::Catalog,
37    Renderer: 'a + core::Renderer + core::text::Renderer,
38{
39    iced_widget::button(
40        text(content)
41            .size(14)
42            .line_height(text::LineHeight::Absolute(core::Pixels(20.0)))
43            .align_x(core::Alignment::Center),
44    )
45    .on_press(message)
46    .height(32)
47    .width(core::Length::Fill)
48}