summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-07-08 08:25:56 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-07-08 11:29:21 +0200
commit21b583c46899d8f31ea39ede7194abf6f61df636 (patch)
tree0f43d159345d2b6150f9ffd7d516d1563fd26a9d /native
parent105c0fe4780233670191abe50ddc922a553ffd63 (diff)
downloadiced-21b583c46899d8f31ea39ede7194abf6f61df636.tar.gz
iced-21b583c46899d8f31ea39ede7194abf6f61df636.tar.bz2
iced-21b583c46899d8f31ea39ede7194abf6f61df636.zip
Avoid reopening `Menu` in `ComboBox`
Diffstat (limited to 'native')
-rw-r--r--native/src/widget/combo_box.rs30
1 files changed, 19 insertions, 11 deletions
diff --git a/native/src/widget/combo_box.rs b/native/src/widget/combo_box.rs
index 4d020c3b..9447b9dd 100644
--- a/native/src/widget/combo_box.rs
+++ b/native/src/widget/combo_box.rs
@@ -19,6 +19,7 @@ where
text_size: Option<u16>,
font: Renderer::Font,
style: <Renderer as self::Renderer>::Style,
+ is_open: bool,
}
#[derive(Default)]
@@ -38,6 +39,8 @@ where
selected: Option<T>,
on_selected: impl Fn(T) -> Message + 'static,
) -> Self {
+ let is_open = state.menu.is_open();
+
Self {
menu: &mut state.menu,
on_selected: Box::new(on_selected),
@@ -48,6 +51,7 @@ where
padding: Renderer::DEFAULT_PADDING,
font: Default::default(),
style: Default::default(),
+ is_open,
}
}
@@ -179,19 +183,23 @@ where
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>,
) {
- match event {
- Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => {
- if layout.bounds().contains(cursor_position) {
- let selected = self.selected.as_ref();
-
- self.menu.open(
- self.options
- .iter()
- .position(|option| Some(option) == selected),
- );
+ if !self.is_open {
+ match event {
+ Event::Mouse(mouse::Event::ButtonPressed(
+ mouse::Button::Left,
+ )) => {
+ if layout.bounds().contains(cursor_position) {
+ let selected = self.selected.as_ref();
+
+ self.menu.open(
+ self.options
+ .iter()
+ .position(|option| Some(option) == selected),
+ );
+ }
}
+ _ => {}
}
- _ => {}
}
}