diff options
| author | 2022-07-26 16:46:12 -0300 | |
|---|---|---|
| committer | 2023-01-09 11:27:04 -0800 | |
| commit | 35331d0a41a53b8ff5c642b8274c7377ae6c6182 (patch) | |
| tree | 522f9cded3072b64b1127fe9ad572c3f0224cecc /examples | |
| parent | 3d901d5f1f8e496651a6f9881fec92bc8998d910 (diff) | |
| download | iced-35331d0a41a53b8ff5c642b8274c7377ae6c6182.tar.gz iced-35331d0a41a53b8ff5c642b8274c7377ae6c6182.tar.bz2 iced-35331d0a41a53b8ff5c642b8274c7377ae6c6182.zip  | |
Allow closing the window from user code
Diffstat (limited to '')
| -rw-r--r-- | examples/multi_window/src/main.rs | 9 | 
1 files changed, 7 insertions, 2 deletions
diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs index 4ad92adb..ca137d48 100644 --- a/examples/multi_window/src/main.rs +++ b/examples/multi_window/src/main.rs @@ -50,6 +50,7 @@ enum WindowMessage {      Close(pane_grid::Pane),      CloseFocused,      SelectedWindow(pane_grid::Pane, SelectableWindow), +    CloseWindow,  }  impl Application for Example { @@ -128,6 +129,9 @@ impl Application for Example {                  let window = self.windows.get_mut(&id).unwrap();                  window.focus = Some(pane);              } +            WindowMessage::CloseWindow => { +                let _ = self.windows.remove(&id); +            }              WindowMessage::Resized(pane_grid::ResizeEvent { split, ratio }) => {                  let window = self.windows.get_mut(&id).unwrap();                  window.panes.resize(&split, ratio); @@ -145,8 +149,6 @@ impl Application for Example {                      if let Some((pane, _)) = result {                          window.focus = Some(pane);                      } - -                    self.panes_created += 1;                  }              }              WindowMessage::ToggleMoving(pane) => { @@ -260,6 +262,9 @@ impl Application for Example {                      WindowMessage::TitleChanged,                  ),                  button(text("Apply")).style(theme::Button::Primary), +                button(text("Close")) +                    .on_press(WindowMessage::CloseWindow) +                    .style(theme::Button::Destructive),              ]              .spacing(5)              .align_items(Alignment::Center);  | 
