diff options
| author | pml68 <contact@pml68.dev> | 2025-05-13 00:47:45 +0200 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-05-13 00:54:08 +0200 |
| commit | 0ad1bef11d3180e569d84ab504343db7fcc5452a (patch) | |
| tree | d67e52bf44723d17dfdc657be70ccbb7ee1ba71a /src | |
| parent | feat: add `backdrop` method to `Dialog` (diff) | |
| download | iced_dialog-0ad1bef11d3180e569d84ab504343db7fcc5452a.tar.gz | |
feat: add example code to documentation and README
Diffstat (limited to '')
| -rw-r--r-- | src/lib.rs | 64 |
1 files changed, 63 insertions, 1 deletions
@@ -1,7 +1,69 @@ //! Custom dialog for `iced` //! //! # Example -//! See [here](https://github.com/pml68/iced_dialog/tree/master/example) +//! ```no_run +//! use iced::{ +//! Element, Length, Task, +//! widget::{button, center, column, text}, +//! }; +//! use iced_dialog::dialog; +//! +//! #[derive(Default)] +//! struct State { +//! is_open: bool, +//! action_text: String, +//! } +//! +//! #[derive(Debug, Clone)] +//! enum Message { +//! OpenDialog, +//! Saved, +//! Cancelled, +//! } +//! +//! fn main() -> iced::Result { +//! iced::run(State::update, State::view) +//! } +//! +//! impl State { +//! fn update(&mut self, message: Message) -> Task<Message> { +//! match message { +//! Message::OpenDialog => self.is_open = true, +//! Message::Saved => { +//! self.action_text = "User saved their work".to_owned(); +//! self.is_open = false; +//! } +//! Message::Cancelled => { +//! self.action_text = "User cancelled the dialog".to_owned(); +//! self.is_open = false; +//! } +//! } +//! Task::none() +//! } +//! +//! fn view(&self) -> Element<'_, Message> { +//! let base = center( +//! column![ +//! text(&self.action_text), +//! button("Open Dialog").on_press(Message::OpenDialog) +//! ] +//! .spacing(14.0), +//! ) +//! .width(Length::Fill) +//! .height(Length::Fill); +//! +//! let dialog_content = text("Do you want to save?"); +//! +//! dialog(self.is_open, base, dialog_content) +//! .title("Save") +//! .push_button(iced_dialog::button("Save", Message::Saved)) +//! .push_button(iced_dialog::button("Cancel", Message::Cancelled)) +//! .width(350) +//! .height(234) +//! .into() +//! } +//! } +//! ``` pub mod dialog; pub use dialog::Dialog; use iced_core as core; |
