From aeae94d31b85d2a07143ce2a6f31e68923b51902 Mon Sep 17 00:00:00 2001 From: Jack hollis-london Date: Mon, 7 Mar 2022 00:30:32 +0000 Subject: [PATCH] small refactor per code review --- common/src/trade.rs | 2 +- voxygen/src/hud/mod.rs | 13 ++++++------- voxygen/src/hud/trade.rs | 6 +++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/common/src/trade.rs b/common/src/trade.rs index 6326a13adb..f568f285c1 100644 --- a/common/src/trade.rs +++ b/common/src/trade.rs @@ -195,7 +195,7 @@ impl PendingTrade { self.accept_flags = [false, false]; } }, - _ => {}, + Decline => {}, } } } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 60dfb92825..dfcea44cb0 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -3893,17 +3893,16 @@ impl Hud { scale_mode } - /// Checks if a TextEdit widget has the keyboard captured. - fn typing(&self) -> bool { Hud::_typing(&self.ui.ui) } - /// reusable function, avoids duplicating code - fn _typing(ui: &conrod_core::Ui) -> bool { + /// Checks if a TextEdit widget has the keyboard captured. + fn typing(&self) -> bool { Hud::is_captured::(&self.ui.ui) } + + /// Checks if a widget of type `W` has captured the keyboard + fn is_captured(ui: &conrod_core::Ui) -> bool { if let Some(id) = ui.global_input().current.widget_capturing_keyboard { ui.widget_graph() .widget(id) - .filter(|c| { - c.type_id == std::any::TypeId::of::<::State>() - }) + .filter(|c| c.type_id == std::any::TypeId::of::<::State>()) .is_some() } else { false diff --git a/voxygen/src/hud/trade.rs b/voxygen/src/hud/trade.rs index d862054329..7e6a6a550b 100644 --- a/voxygen/src/hud/trade.rs +++ b/voxygen/src/hud/trade.rs @@ -599,7 +599,11 @@ impl<'a> Trade<'a> { .graphics_for(state.ids.amount_open_btn) .set(state.ids.amount_open_ovlay, ui); } else if let Some(key) = &mut self.show.trade_amount_input_key { - if selected.is_some() || (!Hud::_typing(ui) && key.input_painted) { + if selected.is_some() + || (!Hud::is_captured::(ui) && key.input_painted) + { + // If the user has selected an item, or if the text edit is not captured, then + // we can close the text edit. event = Some(Err(HudUpdate::Clear)); } key.input_painted = true;