From 3e73fba165e6c4ca0405b3c9b618c7231147e4d0 Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Sun, 26 Jun 2022 00:27:20 +0300 Subject: [PATCH] Better naming for shortened key functions * Old display_shortened that returned Option is now called try_shortened * What was called try_shortened is now just display_shortest, because if shortened version isn't available, it means that regular version is already shortened. --- voxygen/src/hud/buttons.rs | 2 +- voxygen/src/hud/diary.rs | 2 +- voxygen/src/hud/map.rs | 2 +- voxygen/src/hud/settings_window/controls.rs | 2 +- voxygen/src/hud/skillbar.rs | 2 +- voxygen/src/window.rs | 15 +++++++++------ 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/voxygen/src/hud/buttons.rs b/voxygen/src/hud/buttons.rs index d6828466d5..7f56f33a04 100644 --- a/voxygen/src/hud/buttons.rs +++ b/voxygen/src/hud/buttons.rs @@ -425,7 +425,7 @@ impl<'a> Buttons<'a> { text: widget::Id, ) { let key_layout = &self.global_state.window.key_layout; - let key_desc = key_mouse.try_shortened(key_layout); + let key_desc = key_mouse.display_shortest(key_layout); //Create shadow Text::new(&key_desc) diff --git a/voxygen/src/hud/diary.rs b/voxygen/src/hud/diary.rs index 796212992d..e1c72f3ba2 100644 --- a/voxygen/src/hud/diary.rs +++ b/voxygen/src/hud/diary.rs @@ -878,7 +878,7 @@ impl<'a> Widget for Diary<'a> { ] .get(i) .and_then(|input| keys.get_binding(*input)) - .map(|key| key.try_shortened(key_layout)) + .map(|key| key.display_shortest(key_layout)) .unwrap_or_default(); Text::new(&ability_key) diff --git a/voxygen/src/hud/map.rs b/voxygen/src/hud/map.rs index 465af007fd..04e1d881c7 100644 --- a/voxygen/src/hud/map.rs +++ b/voxygen/src/hud/map.rs @@ -1425,7 +1425,7 @@ impl<'a> Widget for Map<'a> { .color(TEXT_COLOR) .set(state.ids.zoom_txt, ui); - Text::new(&location_marker_binding.try_shortened(key_layout)) + Text::new(&location_marker_binding.display_shortest(key_layout)) .right_from(state.ids.zoom_txt, 15.0) .font_size(self.fonts.cyri.scale(14)) .font_id(self.fonts.cyri.conrod_id) diff --git a/voxygen/src/hud/settings_window/controls.rs b/voxygen/src/hud/settings_window/controls.rs index c8ee72dabc..11c11309a7 100644 --- a/voxygen/src/hud/settings_window/controls.rs +++ b/voxygen/src/hud/settings_window/controls.rs @@ -134,7 +134,7 @@ impl<'a> Widget for Controls<'a> { format!( "{} {}", key.display_string(key_layout), - key.display_shortened(key_layout) + key.try_shortened(key_layout) .map_or("".to_owned(), |short| format!("({})", short)) ), if controls.has_conflicting_bindings(key) { diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index 694867c709..cc929a8f59 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -655,7 +655,7 @@ impl<'a> Skillbar<'a> { let position_bg = entry.shortcut_position_bg; let (id, id_bg) = entry.shortcut_widget_ids; - let key_desc = key.try_shortened(key_layout); + let key_desc = key.display_shortest(key_layout); // shortcut text Text::new(&key_desc) .position(position) diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 96e8263cc6..d9daa308b2 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -344,10 +344,9 @@ impl KeyMouse { key_string.to_owned() } - /// Returns shortened key name (e.g. Left Click -> LMB) - /// - /// Use it in case if space does really matter. - pub fn display_shortened(&self, _key_layout: &Option) -> Option { + /// If it exists, returns the shortened version of a key name + /// (e.g. Left Click -> M1) + pub fn try_shortened(&self, _key_layout: &Option) -> Option { use self::KeyMouse::*; use winit::event::{MouseButton, VirtualKeyCode::*}; let key_string = match self { @@ -367,8 +366,12 @@ impl KeyMouse { Some(key_string.to_owned()) } - pub fn try_shortened(&self, key_layout: &Option) -> String { - self.display_shortened(key_layout) + /// Returns shortest name of key (e.g. Left Click - M1) + /// If key doesn't have shorter version, use regular one. + /// + /// Use it in case if space does really matter. + pub fn display_shortest(&self, key_layout: &Option) -> String { + self.try_shortened(key_layout) .unwrap_or_else(|| self.display_string(key_layout)) } }