fix(popover): add modal property for dialogs
Fixes quirks with the context drawer and dialogs
This commit is contained in:
parent
c6ab6cfe23
commit
2bfdc09a43
2 changed files with 16 additions and 6 deletions
|
|
@ -34,6 +34,7 @@ pub enum Position {
|
|||
#[must_use]
|
||||
pub struct Popover<'a, Message, Renderer> {
|
||||
content: Element<'a, Message, crate::Theme, Renderer>,
|
||||
modal: bool,
|
||||
// XXX Avoid refcell; improve iced overlay API?
|
||||
popup: Option<RefCell<Element<'a, Message, crate::Theme, Renderer>>>,
|
||||
position: Position,
|
||||
|
|
@ -43,11 +44,18 @@ impl<'a, Message, Renderer> Popover<'a, Message, Renderer> {
|
|||
pub fn new(content: impl Into<Element<'a, Message, crate::Theme, Renderer>>) -> Self {
|
||||
Self {
|
||||
content: content.into(),
|
||||
modal: false,
|
||||
popup: None,
|
||||
position: Position::Center,
|
||||
}
|
||||
}
|
||||
|
||||
/// A modal popup interrupts user inputs and demands action.
|
||||
pub fn modal(mut self, modal: bool) -> Self {
|
||||
self.modal = modal;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn popup(mut self, popup: impl Into<Element<'a, Message, crate::Theme, Renderer>>) -> Self {
|
||||
self.popup = Some(RefCell::new(popup.into()));
|
||||
self
|
||||
|
|
@ -127,11 +135,13 @@ where
|
|||
shell: &mut Shell<'_, Message>,
|
||||
viewport: &Rectangle,
|
||||
) -> event::Status {
|
||||
if matches!(
|
||||
event,
|
||||
Event::Mouse(mouse::Event::ButtonPressed(_))
|
||||
| Event::Touch(touch::Event::FingerPressed { .. })
|
||||
) {
|
||||
if !self.modal
|
||||
&& matches!(
|
||||
event,
|
||||
Event::Mouse(mouse::Event::ButtonPressed(_))
|
||||
| Event::Touch(touch::Event::FingerPressed { .. })
|
||||
)
|
||||
{
|
||||
let state = tree.state.downcast_mut::<State>();
|
||||
state.is_open = cursor_position.is_over(layout.bounds());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue