From 9023386e723decdd3b19e410a4d15ec3b10be489 Mon Sep 17 00:00:00 2001 From: grzi Date: Thu, 24 Dec 2020 09:35:03 +0100 Subject: [PATCH] fix: Fixed ui deprecated and missing resource --- amethyst_ui/src/bundle.rs | 1 + amethyst_ui/src/text_editing.rs | 39 +++++++++++++++------------------ 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/amethyst_ui/src/bundle.rs b/amethyst_ui/src/bundle.rs index 582c90f82d..f56e85922c 100644 --- a/amethyst_ui/src/bundle.rs +++ b/amethyst_ui/src/bundle.rs @@ -49,6 +49,7 @@ where builder: &mut DispatcherBuilder, ) -> Result<(), Error> { resources.insert(EventChannel::::new()); + resources.insert(EventChannel::::new()); resources.insert(Widgets::::new()); resources.insert(CachedSelectionOrderResource::default()); diff --git a/amethyst_ui/src/text_editing.rs b/amethyst_ui/src/text_editing.rs index 47fab62955..4fdca2e93c 100644 --- a/amethyst_ui/src/text_editing.rs +++ b/amethyst_ui/src/text_editing.rs @@ -4,16 +4,14 @@ use amethyst_core::{ ecs::*, shrev::{EventChannel, ReaderId}, }; +use amethyst_input::{InputHandler, KeyboardModifiersState}; use copypasta::{ClipboardContext, ClipboardProvider}; use log::error; use unicode_normalization::{char::is_combining_mark, UnicodeNormalization}; use unicode_segmentation::UnicodeSegmentation; -use winit::event::{ - ElementState, Event, KeyboardInput, ModifiersState, VirtualKeyCode, WindowEvent, -}; +use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}; use crate::{LineMode, Selected, TextEditing, UiEvent, UiEventType, UiText}; - /// System managing the keyboard inputs for the editable text fields. /// ## Features /// * Adds and removes text. @@ -38,9 +36,10 @@ impl System<'static> for TextEditingInputSystem { SystemBuilder::new("TextEditingInputSystem") .read_resource::>>() .write_resource::>() + .read_resource::() .with_query(<&mut UiText>::query()) .with_query(<(Entity, &mut UiText, &mut TextEditing, &Selected)>::query()) - .build(move |_commands, world, (events, ui_events), + .build(move |_commands, world, (events, ui_events, inputs), (ui_texts_query, selected_ui_texts_query)| { ui_texts_query.for_each_mut(world, |mut text| { @@ -88,8 +87,6 @@ impl System<'static> for TextEditingInputSystem { KeyboardInput { state: ElementState::Pressed, virtual_keycode: Some(v_keycode), - - modifiers, .. }, .. @@ -97,7 +94,7 @@ impl System<'static> for TextEditingInputSystem { .. } => match v_keycode { VirtualKeyCode::Home | VirtualKeyCode::Up => { - focused_edit.highlight_vector = if modifiers.shift() { + focused_edit.highlight_vector = if inputs.modifiers.shift() { focused_edit.cursor_position } else { 0 @@ -107,7 +104,7 @@ impl System<'static> for TextEditingInputSystem { } VirtualKeyCode::End | VirtualKeyCode::Down => { let glyph_len = focused_text.text.graphemes(true).count() as isize; - focused_edit.highlight_vector = if modifiers.shift() { + focused_edit.highlight_vector = if inputs.modifiers.shift() { focused_edit.cursor_position - glyph_len } else { 0 @@ -146,9 +143,9 @@ impl System<'static> for TextEditingInputSystem { } } VirtualKeyCode::Left => { - if focused_edit.highlight_vector == 0 || modifiers.shift() { + if focused_edit.highlight_vector == 0 || inputs.modifiers.shift() { if focused_edit.cursor_position > 0 { - let delta = if ctrl_or_cmd(modifiers) { + let delta = if ctrl_or_cmd(&inputs.modifiers) { let mut graphemes = 0; for word in focused_text.text.split_word_bounds() { let word_graphemes = @@ -165,7 +162,7 @@ impl System<'static> for TextEditingInputSystem { 1 }; focused_edit.cursor_position -= delta; - if modifiers.shift() { + if inputs.modifiers.shift() { focused_edit.highlight_vector += delta; } focused_edit.cursor_blink_timer = 0.0; @@ -178,10 +175,10 @@ impl System<'static> for TextEditingInputSystem { } } VirtualKeyCode::Right => { - if focused_edit.highlight_vector == 0 || modifiers.shift() { + if focused_edit.highlight_vector == 0 || inputs.modifiers.shift() { let glyph_len = focused_text.text.graphemes(true).count(); if (focused_edit.cursor_position as usize) < glyph_len { - let delta = if ctrl_or_cmd(modifiers) { + let delta = if ctrl_or_cmd(&inputs.modifiers) { let mut graphemes = 0; for word in focused_text.text.split_word_bounds() { graphemes += word.graphemes(true).count() as isize; @@ -194,7 +191,7 @@ impl System<'static> for TextEditingInputSystem { 1 }; focused_edit.cursor_position += delta; - if modifiers.shift() { + if inputs.modifiers.shift() { focused_edit.highlight_vector -= delta; } focused_edit.cursor_blink_timer = 0.0; @@ -207,14 +204,14 @@ impl System<'static> for TextEditingInputSystem { } } VirtualKeyCode::A => { - if ctrl_or_cmd(modifiers) { + if ctrl_or_cmd(&inputs.modifiers) { let glyph_len = focused_text.text.graphemes(true).count() as isize; focused_edit.cursor_position = glyph_len; focused_edit.highlight_vector = -glyph_len; } } VirtualKeyCode::X => { - if ctrl_or_cmd(modifiers) { + if ctrl_or_cmd(&inputs.modifiers) { let new_clip = extract_highlighted(focused_edit, focused_text); if !new_clip.is_empty() { match ClipboardContext::new().and_then( @@ -233,7 +230,7 @@ impl System<'static> for TextEditingInputSystem { } } VirtualKeyCode::C => { - if ctrl_or_cmd(modifiers) { + if ctrl_or_cmd(&inputs.modifiers) { let new_clip = read_highlighted(focused_edit, focused_text); if !new_clip.is_empty() { if let Err(e) = ClipboardContext::new().and_then( @@ -247,7 +244,7 @@ impl System<'static> for TextEditingInputSystem { } } VirtualKeyCode::V => { - if ctrl_or_cmd(modifiers) { + if ctrl_or_cmd(&inputs.modifiers) { delete_highlighted(focused_edit, focused_text); match ClipboardContext::new() @@ -289,7 +286,7 @@ impl System<'static> for TextEditingInputSystem { )); } LineMode::Wrap => { - if modifiers.shift() { + if inputs.modifiers.shift() { if focused_text.text.graphemes(true).count() < focused_edit.max_length { @@ -330,7 +327,7 @@ impl System<'static> for TextEditingInputSystem { } /// Returns if the command key is down on OSX, and the CTRL key for everything else. -fn ctrl_or_cmd(modifiers: ModifiersState) -> bool { +fn ctrl_or_cmd(modifiers: &KeyboardModifiersState) -> bool { (cfg!(target_os = "macos") && modifiers.logo()) || (cfg!(not(target_os = "macos")) && modifiers.ctrl()) }