From 9d928261cbce1d136d85352a715e974c163935d9 Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Sat, 25 Jun 2022 17:10:22 +0300 Subject: [PATCH] Try to display shortened version of key in diary * Make try_shortened method that tries shortened version of key or regular version if shortened one isn't available * Use it in most places where display_shortened + display_string were used * Use it for diary skilbar --- voxygen/src/hud/buttons.rs | 4 +--- voxygen/src/hud/diary.rs | 2 +- voxygen/src/hud/map.rs | 18 +++++++----------- voxygen/src/hud/skillbar.rs | 4 +--- voxygen/src/window.rs | 5 +++++ 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/voxygen/src/hud/buttons.rs b/voxygen/src/hud/buttons.rs index 133cd3f749..d6828466d5 100644 --- a/voxygen/src/hud/buttons.rs +++ b/voxygen/src/hud/buttons.rs @@ -425,9 +425,7 @@ impl<'a> Buttons<'a> { text: widget::Id, ) { let key_layout = &self.global_state.window.key_layout; - let key_desc = key_mouse - .display_shortened(key_layout) - .unwrap_or_else(|| key_mouse.display_string(key_layout)); + let key_desc = key_mouse.try_shortened(key_layout); //Create shadow Text::new(&key_desc) diff --git a/voxygen/src/hud/diary.rs b/voxygen/src/hud/diary.rs index b7eeff1f87..796212992d 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.display_string(key_layout)) + .map(|key| key.try_shortened(key_layout)) .unwrap_or_default(); Text::new(&ability_key) diff --git a/voxygen/src/hud/map.rs b/voxygen/src/hud/map.rs index 60e1c2862f..465af007fd 100644 --- a/voxygen/src/hud/map.rs +++ b/voxygen/src/hud/map.rs @@ -1425,17 +1425,13 @@ impl<'a> Widget for Map<'a> { .color(TEXT_COLOR) .set(state.ids.zoom_txt, ui); - Text::new( - &location_marker_binding - .display_shortened(key_layout) - .unwrap_or_default(), - ) - .right_from(state.ids.zoom_txt, 15.0) - .font_size(self.fonts.cyri.scale(14)) - .font_id(self.fonts.cyri.conrod_id) - .graphics_for(state.ids.map_layers[0]) - .color(TEXT_COLOR) - .set(state.ids.waypoint_binding_txt, ui); + Text::new(&location_marker_binding.try_shortened(key_layout)) + .right_from(state.ids.zoom_txt, 15.0) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) + .graphics_for(state.ids.map_layers[0]) + .color(TEXT_COLOR) + .set(state.ids.waypoint_binding_txt, ui); Text::new(i18n.get("hud.map.mid_click")) .right_from(state.ids.waypoint_binding_txt, 5.0) diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index 3c178504e5..694867c709 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -655,9 +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 - .display_shortened(key_layout) - .unwrap_or_else(|| key.display_string(key_layout)); + let key_desc = key.try_shortened(key_layout); // shortcut text Text::new(&key_desc) .position(position) diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 5275117f31..96e8263cc6 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -366,6 +366,11 @@ impl KeyMouse { Some(key_string.to_owned()) } + + pub fn try_shortened(&self, key_layout: &Option) -> String { + self.display_shortened(key_layout) + .unwrap_or_else(|| self.display_string(key_layout)) + } } pub struct Window {