Avoid reopening Menu
in ComboBox
This commit is contained in:
parent
105c0fe478
commit
21b583c468
@ -19,6 +19,7 @@ where
|
|||||||
text_size: Option<u16>,
|
text_size: Option<u16>,
|
||||||
font: Renderer::Font,
|
font: Renderer::Font,
|
||||||
style: <Renderer as self::Renderer>::Style,
|
style: <Renderer as self::Renderer>::Style,
|
||||||
|
is_open: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -38,6 +39,8 @@ where
|
|||||||
selected: Option<T>,
|
selected: Option<T>,
|
||||||
on_selected: impl Fn(T) -> Message + 'static,
|
on_selected: impl Fn(T) -> Message + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
let is_open = state.menu.is_open();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
menu: &mut state.menu,
|
menu: &mut state.menu,
|
||||||
on_selected: Box::new(on_selected),
|
on_selected: Box::new(on_selected),
|
||||||
@ -48,6 +51,7 @@ where
|
|||||||
padding: Renderer::DEFAULT_PADDING,
|
padding: Renderer::DEFAULT_PADDING,
|
||||||
font: Default::default(),
|
font: Default::default(),
|
||||||
style: Default::default(),
|
style: Default::default(),
|
||||||
|
is_open,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,8 +183,11 @@ where
|
|||||||
_renderer: &Renderer,
|
_renderer: &Renderer,
|
||||||
_clipboard: Option<&dyn Clipboard>,
|
_clipboard: Option<&dyn Clipboard>,
|
||||||
) {
|
) {
|
||||||
|
if !self.is_open {
|
||||||
match event {
|
match event {
|
||||||
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
|
Event::Mouse(mouse::Event::ButtonPressed(
|
||||||
|
mouse::Button::Left,
|
||||||
|
)) => {
|
||||||
if layout.bounds().contains(cursor_position) {
|
if layout.bounds().contains(cursor_position) {
|
||||||
let selected = self.selected.as_ref();
|
let selected = self.selected.as_ref();
|
||||||
|
|
||||||
@ -194,6 +201,7 @@ where
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
&self,
|
&self,
|
||||||
|
Loading…
Reference in New Issue
Block a user